End If End Sub
4.块形式的if嵌套 If 条件判断 then 成立时的结果 Elseif 条件判断 then 成立时的结果 …… Else
不成立时的结果 End if 1-13
Select case 语句 根据表达式的值,来决定执行几组语句中的其中之一。
sub select单条件判断() i = -1 Select Case i Case Is > 0 MsgBox \正数\ Case Else MsgBox \负数\ End Select
End Sub
1-14 循环语句之DO…LOOP
Do……loop循环语句,直到满足某个条件 Sub 基本示例() Dim a% Do a = a + 1 If a > 10 Then
MsgBox a & \终于大于10\Exit Do End If Loop End Sub
1-15 循环语句do loop 实例 Sub 基本示例() Dim rs% rs = 1 Do rs = rs + 1 If rs > 10 Then Exit Do 'exit sub Else
If Cells(rs, 2) >= 90 Then Cells(rs, 3) = \√\ End If Loop End Sub
Sub 循环语句while() Dim rs% rs = 2
Do While Cells(rs, 2) <> \
If Cells(rs, 2) > 90 Then Cells(rs, 3) = \√\ rs = rs + 1 Loop End Sub
1-17 循环语句 do until Sub dountil() Dim rs% rs = 2
Do Until Cells(rs, 2) = \
If Cells(rs, 2) > 90 Then Cells(rs, 3) = \√\ rs = rs + 1 Loop End Sub Sub 隔行填色()
Dim rs% rs = 2
Do Until Cells(rs, 1) = \
Range(\ rs = rs + 2 Loop End Sub
1-18 循环语句之while与until位置变化
While与until不但可以放在do后面,也可以放在loop后面 事实上有时在循环的最后一行进行判断,更具有意义。 Sub doloop的最后判断循环() Dim pss$, i% Do i = i + 1
If i > 3 Then Exit Do
pss = InputBox(\请输入密码:\Loop Until pss = \loop while pss<>”123” End Sub
1-18b do…loop语法小结 'do [{while | until} 表达式] '[执行的一条或多条语句] '[exit do]
相关推荐: