Excel Functions Tutorials

- VBA
- VBA Tutorial
- VBA Functions in Excel
- VBA ArrayList
- VBA Arrays Function in Excel
- VBA Activate Sheet
- VBA Break
- VBA Borders
- VBA Boolean
- VBA ByRef
- VBA Code
- VBA Const
- VBA Class Modules
- VBA Count
- VBA COUNTA
- VBA COUNTIF
- VBA Comment Block
- VBA Match Function
- VBA LEFT Function
- VBA Right Function
- VBA Like
- VBA LEN
- VBA Long
- VBA Today
- VBA Now
- VBA Time Function
- VBA Timer
- VBA TimeValue
- VBA Weekday
- VBA ROUND
- VBA RoundUp
- VBA Random Numbers
- VBA ReDIM Function
- VBA Rename Sheet
- VBA Protect Sheet
- VBA Remove Duplicates
- VBA Concatenate
- Copy Paste in VBA
- VBA Paste
- VBA Print
- VBA Date Function
- VBA DateDiff Function
- VBA DateAdd Function
- VBA DatePart
- VBA Data Type
- VBA Dictionary
- VBA Debug Print
- VBA Charts
- VBA CDBL
- VBA CSTR
- VBA Chr
- VBA ChDir
- VBA ENUM
- VBA RegEx
- VBA Mid Function
- VBA Max
- VBA Find Function
- VBA Find and Replace
- VBA Trim Function
- VBA Text
- VBA OFFSET Function
- VBA MOD Function
- VBA Split Function
- VBA UBound Function
- VBA Union
- VBA Transpose
- VBA INT
- VBA InStr
- VBA INSTRREV
- VBA Intersect
- VBA Integer
- VBA DIR Function
- VBA OR Function
- VBA AND
- VBA Operators
- VBA Not Equal
- VBA Worksheet Function
- VBA Workbook
- VBA ThisWorkbook
- VBA Worksheets
- VBA Write Text File
- VBA Hyperlinks
- VBA String Functions
- VBA StrComp
- VBA StrConv
- VBA Sub
- VBA Call Sub
- VBA End
- VBA Wait
- VBA Option Explicit
- VBA SubString
- VBA Subscript Out of Range
- VBA IIF
- VBA IF OR
- VBA IFERROR
- VBA On Error
- VBA OverFlow Error
- VBA 1004 Error
- VBA Error Handling
- VBA Type
- VBA Type Mismatch Error
- VBA IsEmpty
- VBA ISNULL
- VBA Input Box
- VBA MsgBox
- VBA Text Box
- VBA Format
- VBA Format Number
- VBA Conditional Formatting
- VBA AutoFill
- VBA AutoFilter
- VBA Color Index
- VBA Font Color
- VBA Clear Contents
- VBA Collection
- VBA Paste Special
- VBA Progress Bar
- VBA GoTo
- VBA Userform
- VBA Close UserForm
- User Defined Function in Excel VBA
- VBA Outlook
- VBA JOIN
- VBA LCase
- VBA UCase
- VBA Select Case
- VBA Select Cell
- VBA Selection
- VBA Active Cell
- VBA Set
- VBA Sleep
- VBA Pause
- VBA Range Objects
- VBA Range Cells
- VBA UsedRange
- VBA Loop
- VBA Break For Loop
- VBA For Each Loop
- VBA For Next Loop
- VBA Do Until Loop
- VBA File Copy
- VBA FileDialog
- VBA FileSystemObject (FSO)
- VBA Cells
- VBA Last Row
- VBA Insert Row
- VBA Hide Columns
- VBA New Line
- VBA GetOpenFilename
- VBA GetObject
- VBA Delete File
- VBA Delete Row
- VBA Insert Columns
- VBA Delete Column
- VBA Val
- VBA Value
- VBA Variant
- VBA Variable Declaration
- VBA Global Variables
- VBA Pivot Table
- VBA Refresh Pivot Table
- VBA PowerPoint
- VBA Send Email from Excel

- Financial Functions in Excel (17+)
- Logical Functions in Excel (15+)
- TEXT Functions in Excel (29+)
- Lookup Reference in Excel (44+)
- Maths Functions in Excel (52+)
- Date and Time Function in Excel (22+)
- Statistical Function in Excel (50+)
- Information Functions in Excel (5+)
- Excel Charts (48+)
- Excel Tools (98+)
- Excel Tips (178+)

Related Courses

In VBA operators are as important as they are in other languages or work, in VBA we can use all the operators such as addition, multiplication subtraction division assignment or the logical operators, the method is similar to use the operators as we use in excel such as A>B is using a comparison operator.

## What are Operators in VBA?

It doesn’t matter how good we are or how proficient we are at our work, if we don’t do the basic 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”.

VBA Operators are the heart of any calculation. Operators are the signs we use to compare one thing with another, operators are the signs we use to check whether one number is greater than another or less than another or equal to another number and not equal to as well.

I am sure you must have used these logics in your daily workplace. 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 are the list of those.

### List of Comparison Operators for VBA

**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.

For example an equation 25 = 25 returns TRUE and an equation Hello = Hiii returns FALSE.**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.

For example, an equation 25 > 20 returns TRUE but 25 > 25 returns FALSE because 25 is equal to 25 not greater than that number.**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.**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.

For example an equation 20 < 25 returns TRUE but 25 < 25 returns FALSE because 25 is equal to 25 not greater than that number.**Less Than or Equal to Sign (>=):**This sign works exactly the same as the above VBA operator Less Than but checks whether the number is equal or not.**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.

For example, equation 25 <> 20 returns TRUE because the number 25 is not equal to the number 20. 30 <> 30 returns FALSE because 30 is equal to 30 only.

### Example Code of Operator Sign in VBA

Below are the examples of VBA comparison operators in excel.

4.6 (247 ratings)

#### Example #1 – Equal Sign Code

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.

#### Example #2 – Greater Than Sign Code

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 –

#### Example #3 – Greater Than or Equal to Sign Code

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.

#### Example #4 – Less Than Sign Code

Below is the VBA Code to understand the use of **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.

#### Example #5 – Not Equal to Sign Code

Below is the VBA Code to understand the use of **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 VBA comparison operators along with practical examples and downloadable template codes. You can learn more about VBA from the following articles –

- VBA Switch Case Statement
- Activate Sheet in VBA | Using its Index Number
- What does FileDialog Option do in VBA?
- InStr in VBA
- VBA GetOpenFilename
- List of Logical Operators in Excel
- Step by Step Tutorial in VBA
- Assign Data Type in VBA
- Use IF & AND Function in Excel

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