If Then Else in VBA
Basic Construct
Dim x As Integer x = 5 If x = 5 Then MsgBox "x = 5" End If |
If Then Else
Dim x As Integer x = 5 If x = 5 Then MsgBox "x = 5" Else MsgBox "x <> 5" End If |
If statement with And condition
Dim x As Integer Dim y As Integer x = 5 y = 5 If x = 5 And y = 5 Then MsgBox "x = 5 and y = 5" End If |
If statement with Or condition
Dim x As Integer Dim y As Integer x = 5 y = 5 If x = 5 Or y = 5 Then MsgBox "x = 5 or y = 5" End If |
Multiple conditions in If statement
Dim x As Integer Dim y As Integer x = 5 y = 5 If (x <> 5 Or (x = 5 And y = 5)) Then MsgBox "x = 5 and y = 5" End If |