Comparing
When comparing values use "=" or "<>".
| Symbol | Operator | Notes |
| = | Equal to | Returns True if what is on the left is equal to what is on the right. |
| <> | Not equal to | Returns True if what is on the left is not equal to what is on the right. |
| > | Greater than | Returns True if what is on the left is greater than what is on the right. |
| < | Less than | Returns True if what is on the left is less than what is on the right. |
| >= | Greater than or equal | Returns True if what is on the left is greater than or equal to what is on the right. |
| <= | Less than or equal | Returns True if what is on the left is less than or equal to what is on the right. |
Comparing Objects
When comparing objects use the IS Operator and not "=" or "<>".
This operator is supposed to determine whether two variables refer to the same object but unfortunately it does nor always work.
Dim sheet1 As Worksheet
Dim sheet2 As Worksheet
Set sheet1 = ActiveSheet
Set sheet2 = Sheets("Sheet1")
If (sheet1 Is sheet2) Then
End If
The IsNot is not available in VBA (only [[VB.Net]]).
Combining Comparisons
If you need to test multiple variables at the same time, join your comparison expressions together using logical operators.
| AND | The logical "AND" operator (Boolean). |
| OR | The logical "OR" operator (Boolean). |
| NOT | The logical "NOT" operator (Boolean). |
| EQV | The logical equivalence operator. |
| IMP | The logical implication from two values (Variant). |
| XOR | The logical exclusion operator. |
Comparing Text Strings
You can use "=" and "<>" to compare strings, but you must be careful with case sensitivity.
By default, VBA is case-sensitive, so "Better" is not the same as "better".
To compare text without worrying about capital letters, use the StrComp Function with vbTextCompare.
Debug.Print StrComp("MONDAY", "monday", vbTextCompare) '= 0
If you want to see if a text variable matches a wildcard pattern, use the LIKE Operator.
Debug.Print "ab-cd" Like "ab?cd" '= True
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext