## Excel VBA Operators

In

VBA operatorsare used to check whether one number is greater than another or less than another or equal to another number and not equal to as well. The method is similar to use the operators as we use in excel such as A>B is using a comparison operator.

It doesn’t matter how good we are or how proficient we are at our work. If we don’t do the basics right, then everything will be in a mess. Firstly if we don’t learn the basics right, then we cannot progress to the next level, be it any profession. The reason why I am pressing so much on basics because, in today’s article, we will show you one of the basic concepts, “VBA Operators.”

Operators are the heart of any calculation. They are the signs we use to compare one thing with another. I am sure you must have used these logics in your daily workplace.

### List of Mathematical Operators

Below is the mathematical operator’s list we use regularly.

Above are the mathematical operators and those are common to everybody. We have comparison operators as well. Below is the list of those.

### List of Comparison Operators for VBA

- Equal Sign (=)
- Greater Than Sign (>)
- Greater Than or Equal to Sign (>=)
- Less than Sign (<)
- Not Equal to Sign (<>)

Let’s discuss these operators in detail.

**Equal Sign (=)**

This sign is used to compare whether one thing is equal to another thing. The result of this operator sign is either TRUE or FALSE. If the one thing is equal to another, then we will get TRUE or else FALSE.

Below is the VBA Code to understand the use of **Equal(=)** operator.

**Code:**

Sub Equal_Operator() Dim Val1 As String Dim Val2 As String Val1 = 25 Val2 = 25 If Val1 = Val2 Then MsgBox "Both are same and result is TRUE" Else MsgBox "Both are not same and result is FALSE" End If End Sub

This will return the result as TRUE because variables values “Val1” & “Val2” are the same.

4.6 (247 ratings) 3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion

**Greater Than Sign (>)**

This sign checks whether one number is greater than the other number. This is also a logical VBA operator where the result is either TRUE or FALSE.

Below is the VBA Code to understand the use of **Greater Than (>)** operator.

**Code:**

Sub Greater_Operator() Dim Val1 As String Dim Val2 As String Val1 = 25 Val2 = 20 If Val1 > Val2 Then MsgBox "Val1 is greater than the val2 and result is TRUE" Else MsgBox "Val1 is not greater than the val2 and result is FALSE" End If End Sub

And the result will be –

#### Greater Than or Equal to Sign (>=)

This sign works exactly the same as the above operator Greater Than but checks whether the number is equal or not.

Below is the VBA Code to understand the use of **Greater Than or Equal to(>=)** operator.

**Code:**

Sub Greater_Than_Equal_Operator() Dim Val1 As String Dim Val2 As String Val1 = 25 Val2 = 20 If Val1 >= Val2 Then MsgBox "Val1 is greater than the val2 and result is TRUE" Else MsgBox "Val1 is not greater than the val2 and result is FALSE" End If End Sub

Now we will just change the val2 amount to 25 and then run the code.

Both the results return TRUE because we have applied >= sign.

#### Less than Sign (<)

This sign checks whether one number is less than the other number. This is also a logical operator in VBA, where the result is either TRUE or FALSE.

Below is the VBA Code to understand the use of the **Less Than (<)** operator.

**Code:**

Sub Less_Operator() Dim Val1 As String Dim Val2 As String Val1 = 25 Val2 = 20 If Val1 < Val2 Then MsgBox "Val1 is less than the val2 and result is TRUE" Else MsgBox "Val1 is not less than the val2 and result is FALSE" End If End Sub

This returns FALSE because 25 is not less than 20.

#### Not Equal to Sign (<>)

This not equal to sign is the inverse operator returns inverse results. If the one thing is equal to another, then it returns FALSE or else TRUE.

Below is the Code to understand the use of the VBA **Not** Equal (<>) operator.

**Code:**

Sub NotEqual_Operator() Dim Val1 As String Dim Val2 As String Val1 = 25 Val2 = 20 If Val1 <> Val2 Then MsgBox "Val1 is not equal to val2 and result is TRUE" Else MsgBox "Val1 is equal to val2 and result is FALSE" End If End Sub

You will get the following output.

### Recommended Articles

This has been a guide to VBA Operators. Here we provide the list of mathematical and comparison operators along with practical examples of VBA and a downloadable excel template. You can learn more about VBA from the following articles –

- 3 Courses
- 12 Hands-on Projects
- 43+ Hours
- Full Lifetime Access
- Certificate of Completion