a very easy question: considering an If...Then...Else
instruction in VBA, how can I separate multiple instructions after Then
? In other words, should I write something like
If condition [ Then ]
[ statement1 ] & [statement2]
Else [Else statement] (i.e. using "&"),
or
If condition [ Then ]
[ statement1 ] And [statement2]
Else [Else statement] (i.e. using "And"),
or some other separator/command?
This works with multiple statements:
if condition1 Then stmt1:stmt2 Else if condition2 Then stmt3:stmt4 Else stmt5:stmt6
Or you can split it over multiple lines:
if condition1 Then stmt1:stmt2
Else if condition2 Then stmt3:stmt4
Else stmt5:stmt6
Multiple statements are to be separated by a new line:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With