If Statement
SyntaxGroupIf condexpr Then [instruction] [Else instruction] -or- If condexpr Then statements [ElseIf condexpr Then statements]... [Else statements] End If
Flow ControlDescription
Form 1: Single line if statement. Execute the instruction following the Then if condexpr is True. Otherwise, execute the instruction following the Else. The Else portion is optional.See Also
Form 2: The multiple line if is useful for complex ifs. Each if condexpr is checked in turn. The first True one causes the following statements to be executed. If all are False then the Else's statements are executed. The ElseIf and Else portions are optional.
Form 3: If objexpr's type is the same type or a type descended from objtype the Then portion is executed.
Select Case, Choose( ), If( ), IIf( )
Sub Main S = InputBox("Enter hello, goodbye, dinner or sleep:") S = UCases If S = "HELLO" Then Debug.Print "come in" If S = "GOODBYE" Then Debug.Print "see you later" If S = "DINNER" Then Debug.Print "Please come in." Debug.Print "Dinner will be ready soon." ElseIf S = "SLEEP" Then Debug.Print "Sorry." Debug.Print "We are full for the night" End If End Sub