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

根据分数为职工评定星级

本文为《别怕,Excel VBA其实很简单(第3版)》随书问题参考答案

如果H2单元格中保存的成绩是0到150之间的整数,用Select Case解决的代码可以写为:

Sub 用Slect语句评定星级()
Select Case Cells(2, "H").Value
Case Is < 85 Cells(2, "I").Value = "不评级" Case Is < 100 Cells(2, "I").Value = "一星级" Case Is < 115 Cells(2, "I").Value = "二星级" Case Is < 130 Cells(2, "I").Value = "三星级" Case Is < 150 Cells(2, "I").Value = "四星级" Case Else Cells(2, "I").Value = "五星级" End Select End Sub

用If语句解决的代码可以写为:

Sub 用If语句评定星级()
Dim Cj As Integer
Cj = Cells(2, "H").Value
If Cj < 85 Then Cells(2, "I").Value = "不评级" ElseIf Cj < 100 Then Cells(2, "I").Value = "一星级" ElseIf Cj < 115 Then Cells(2, "I").Value = "二星级" ElseIf Cj < 130 Then Cells(2, "I").Value = "三星级" ElseIf Cj < 150 Then Cells(2, "I").Value = "四星级" ElseIf Cj = 150 Then Cells(2, "I").Value = "五星级" End If End Sub

赞(16)
未经允许不得转载:ExcelHome » 根据分数为职工评定星级
分享到

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

沪公网安备 31011702000001号

征信