Excel宏的应用-成绩分析处理程序[多图]( 二 )


三.平均分

Sub 平均分()
Const studentno = 190
Const xknum = 6
Dim fs(studentno, xknum), pjf3(4, 6), bjrs(4), qxpjf(6)
Dim bj(studentno)
Sheets("高三理").Select
'以下程序段用于求全校平均分
For i = 1 To studentno
 bj(i) = ActiveSheet.Cells(i + 1, 1)
 For j = 1 To xknum
fs(i, j) = ActiveSheet.Cells(i + 1, j + 3)
 Next j
Next i
For i = 1 To xknum
 Sum = 0
For j = 1 To studentno
um = Sum + fs(j, i)
Next j
qxpjf(i) = Sum / (j - 1)
Next i
'以下程序段用于求各班平均分
For j = 1 To 4
For i = 1 To studentno
Ifbj(i) = j + 2 Then
bjrs(j) = bjrs(j) + 1
For k = 1 To xknum
pjf3(j, k) = pjf3(j, k) + fs(i, k)
Next k
End If
Next i
Next j
For j = 1 To 4
 For i = 1 To 6
pjf3(j, i) = pjf3(j, i) / bjrs(j)
 Next i
Next j
'写入各班各科平均分
Sheets("平均分").Select
For i = 1 To 4
 For j = 1 To 6
ActiveSheet.Cells(i + 2, j + 1) = pjf3(i, j)
 Next j
Next i
'写入全校各科平均分
i = 7
For j = 1 To 6
 ActiveSheet.Cells(i, j + 1) = qxpjf(j)
Next j
End Sub

推荐阅读