13

非常に簡単な質問: If...Then...ElseVBA の命令を考えると、どうすれば複数の命令を の後に分離でき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"),

または他のセパレータ/コマンド?

4

2 に答える 2

23

複数のステートメントは改行で区切ります。

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
于 2013-03-17T10:55:31.383 に答える
1

これは複数のステートメントで機能します。

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
于 2015-04-30T20:08:42.263 に答える