VBA Comparison Operators — Shikshaglobe

VBA Comparison Operators allow you to compare two values. The result of the comparison will be a Boolean value (True or False). You can use these operators in conjunction with If, ElseIf, and Select Case Statements.

The following table lists the VBA Comparison Operators:

OperatorDescription

=Equal To

<>Not Equal To

<Less Than >Greater Than

<=Less Than Or Equal To >=Greater Than Or Equal To

VBA Comparison Operators allow you to compare two values. They are useful for making decisions in your code. For example, you might want to know if one value is greater than another. The following table lists the VBA comparison operators.

Comparison operators return a Boolean value of True or False. The following table shows how the operators work with different data types.

OperatorMeaningExample

=Equal to5 = 3 returns False

<>Not equal to5 <> 3 returns True

<=Less than or equal to5 <= 3 returns False >=Greater than or equal to5 >= 3 returns True

<Less than5 < 3 returns False > Greater than 5 > 3 returns True

Not equal: <>

This operator is used to check if two values are not equal. For example, if we have two variables A and B, and we want to check if they are not equal, we would use the following statement:

A <> B

Less than: < This operator is used to check if a value is less than another value. For example, if we have two variables A and B, and we want to check if A is less than B, we would use the following statement: A < B

In Excel VBA, comparison operators are used to compare two values. The result of a comparison operator is always either TRUE or FALSE.

The three main comparison operators are:

Not equal to (<>)

Less than (<) Greater than (>)

There are also a few other comparison operators, which we'll cover later.