如上图所示,使用Excel中的VBA来编写一个程序自动计算四个学生的成绩进行求平均分以及成绩等级的功能。
参考代码:
Option Explicit
Sub 成绩汇总()
Dim average As Double '平均分
Dim level As String '成绩等级
Dim i As Integer
For i = 3 To 15 Step 4
average = (Cells(2, i) + Cells(3, i) + Cells(4, i) + Cells(5, i) + Cells(6, i) + Cells(7, i)) / 6
Cells(8, i) = average
If Cells(8, i) >= 85 Then
level = '棒棒的'
ElseIf Cells(8, i) >= 80 Then
level = '好样的'
ElseIf Cells(8, i) >= 60 Then
level = '再接再厉啊'
Else
level = '回家放牛吧'
End If
Cells(9, i) = level
Next i
End Sub
重要知识点:
If 条件 Then
语句……
Elseif 条件 Then
语句
……
Else
语句
End If
联系客服