<< Click to Display Table of Contents >> If ... Then ... Else (statement) |
If Condition Then
[Statements]
ElseIf Condition Then
[Statements]]...
[Else
[Statements]]
End If
Or:
If Condition Then Statements [Else Statements]
Executes a group of statements if Condition is true. Optionally executes a different group of statements if Condition is false (see also the section Flow control).
See also: Select Case, section Flow control
Example:
Sub IfTest
Dim Gender as String
Gender = InputBox("Enter your gender (m or f)")
If Gender = "m" Then
MsgBox "You are male."
ElseIf Gender = "f" Then
MsgBox "You are female."
Else
MsgBox "Please enter either m or f!"
End If
End Sub