一个非常简单的问题:考虑VBA中的If...Then...Else
指令,如何在Then
之后分隔多条指令?换句话说,我应该写一些类似
If condition [ Then ]
[ statement1 ] & [statement2]
Else [Else statement] (i.e. using "&"),
或
If condition [ Then ]
[ statement1 ] And [statement2]
Else [Else statement] (i.e. using "And"),
或其他一些分隔符/命令?
答案 0 :(得分:19)
多个陈述用新行分隔:
If SkyIsBlue Then
StartEngines
Pollute
ElseIf SkyIsRed Then
StopAttack
Vent
ElseIf SkyIsYellow Then
If Sunset Then
Sleep
ElseIf Sunrise or IsMorning Then
Smoke
GetCoffee
Else
Error
End If
Else
Joke
Laugh
End If
答案 1 :(得分:-2)
这适用于多个陈述:
if condition1 Then stmt1:stmt2 Else if condition2 Then stmt3:stmt4 Else stmt5:stmt6
或者你可以将它分成多行:
if condition1 Then stmt1:stmt2
Else if condition2 Then stmt3:stmt4
Else stmt5:stmt6