Comparing

When comparing values use "=" or "<>".

SymbolOperatorNotes
=Equal toReturns True if what is on the left is equal to what is on the right.
<>Not equal toReturns True if what is on the left is not equal to what is on the right.
>Greater thanReturns True if what is on the left is greater than what is on the right.
<Less thanReturns True if what is on the left is less than what is on the right.
>=Greater than or equalReturns True if what is on the left is greater than or equal to what is on the right.
<=Less than or equalReturns 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.

ANDThe logical "AND" operator (Boolean).
ORThe logical "OR" operator (Boolean).
NOTThe logical "NOT" operator (Boolean).
EQVThe logical equivalence operator.
IMPThe logical implication from two values (Variant).
XORThe 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