In this tutorial, we will show you how to check multiple conditions in an If statement in VBA (Visual Basic for Applications). “If” statements in VBA are quite flexible and powerful tools for controlling the flow of your code. Particularly, multiple conditions in an If statement allow you to test different conditions and perform different actions depending on the results of these tests.
Step 1: Understanding If-Then-Else Statements
The usual syntax for an If-Then statement is:
1 2 3 |
If condition Then ' [stuff that happens if the condition is true] End If |
But often, we need our program to be smarter and to be able to make choices between more than two options. That’s when we would use an If-Then-Else statement. The syntax is:
1 2 3 4 5 |
If condition Then ' [stuff that happens if the condition is true] Else ' [stuff that happens if the condition is false] End If |
Step 2: Checking Multiple Conditions
To check multiple conditions in an If statement, you can use the logical operators “And” & “Or”.
Here’s an example of using “And” operator:
1 2 3 |
If condition1 And condition2 Then ' [stuff that happens if both conditions are true] End If |
And an example using “Or” operator:
1 2 3 |
If condition1 And condition2 Then ' [stuff that happens if both conditions are true] End If |
Step 3: Applying Multiple Condition Check in an Example
Let’s consider an example with multiple conditions:
Assume we have a variable, score, and want to check if it’s greater than 50 AND less than 80. We can build an If-Then-Else statement using the AND operator to check these conditions:
1 2 3 4 5 6 7 8 9 10 |
Sub CheckScore() Dim score As Integer score = 75 If score > 50 And score < 80 Then MsgBox "Score is between 50 and 80" Else MsgBox "Score is not between 50 and 80" End If End Sub |
This code will display the message “Score is between 50 and 80” because a score of 75 meets both conditions.

Conclusion
Checking multiple conditions can improve the logic of your code, making your VBA applications more flexible and dynamic. By applying the AND and OR logical operators in your If-Then-Else statements, you can abstract even more complex logical reasoning into your code.