If...Then...Else

This statement conditionally executes a group of statements, depending on the value of an expression.

Syntax

If condition Then statements [Else elsestatements ]

Or you can use the following block form syntax:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements]] . . .
[Else
[elsestatements]]
End If

Parameters

condition
Numeric or string expression that evaluates to True or False. If condition is Null, condition is treated as False. The TypeOf statement is unsupported.
statement
One or more statements separated by colons. Executed if condition is True.
condition-n
Same as condition.
elseifstatement
One or more statements executed if the associated condition-n is True.
elsestatement
One or more statements executed if no previous condition or condition-n expression is True.

Remarks

With the single-line syntax, it is possible to have multiple statements executed as the result of an If...Then decision. However, they must all be on the same line and separated by colons, as the following code example shows.

If A > 10 Then A = A + 1 : B = B + A : C = C + B

If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement.

A block If statement must be the first statement on a line. The block If must end with an End If statement.