Excel Home
全球知名的Excel资源网站之一

用Do While语句批量为成绩评定等次

本文为:《别怕,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

赞(14)
未经允许不得转载:ExcelHome » 用Do While语句批量为成绩评定等次
分享到

关于我们联系我们
本站特聘法律顾问:李志群律师   沪ICP备11019229号-2

沪公网安备 31011702000001号

征信