If … ElseIf … Else statement

This function enables you to check two conditions and, based on that, then run one of the three statement blocks present. If the ‘IF’ condition is TRUE, IF statement and condition will run if it is FALSE, then the program will check the ‘ELSEIF’ condition. If it is also false, i.e., not applicable, the else statement will come in the loop. This statement will always have a closing ‘END IF’ statement else, VBA will give an error.


Example 1: Write a macro, to check whether the user number entered by the user is positive, negative or equal to zero.


VBA  If ElseIf Else statement1
VBA  If ElseIf Else statement2

Example 2


VBA  If ElseIf Else statement3
VBA  If ElseIf Else statement4

Pin It on Pinterest

Share This