本文为:《别怕,Excel VBA其实特别简单(第3版)》随书问题参考答案
解决这个问题的方法特别多。如果写入单元格中的均是0到100之间的数据,使用Do While语句解决,可以将代码写为:
1、使用开头判断式的Do While语句
Sub 批量为成绩评定等次()
Dim i As Byte
i = 2
Do While Cells(i, "A").Value <> ""
Select Case Range("B" & i).Value
Case Is >= 90
Range("C" & i).Value = "优秀"
Case Is >= 80
Range("C" & i).Value = "良好"
Case Is >= 60
Range("C" & i).Value = "及格"
Case Else
Range("C" & i).Value = "不及格"
End Select
i = i + 1
Loop
End Sub
2、使用结尾判断式的Do While语句
Sub 批量为成绩评定等次()
Dim i As Byte
i = 2
Do
Select Case Range("B" & i).Value
Case Is >= 90
Range("C" & i).Value = "优秀"
Case Is >= 80
Range("C" & i).Value = "良好"
Case Is >= 60
Range("C" & i).Value = "及格"
Case Else
Range("C" & i).Value = "不及格"
End Select
i = i + 1
Loop While Cells(i, "A").Value <> ""
End Sub