简化数据处理,掌握Excel去除空格的高效技巧
651
2022-10-07
根据分数为职工评定星级
本文为《别怕,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 SelectEnd 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 IfEnd Sub
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。