• Skip to primary navigation
  • Skip to main content
  • Skip to footer
WallStreetMojo

Wallstreet Mojo

Wallstreet Mojo

MENUMENU
  • Resources
        • Excel

          • Excel Functions
          • Excel Tools
          • Excel Tips
        • Excel
        • Financial Functions Excel

          • NPV in Excel
          • IRR in excel
          • PV in Excel
        • Financial-Functions-Excel
        • Lookup Functions Excel

          • VLOOKUP
          • HLOOKUP
          • Index Function
        • Lookup-Functions-in-Excel
        • Excel Charts

          • Pareto Chart in Excel
          • Gannt Chart in Excel
          • Waterfall Chart in Excel
        • Excel-Charts
        • VBA

          • VBA Left Function
          • VBA Paste Special
          • VBA Worksheet Function
        • VBA
        • Others

          • Resources (A to Z)
          • Financial Modeling
          • Equity Research
          • Private Equity
          • Corporate Finance
          • Financial Statement Analysis
  • Free Courses
  • All Courses
        • Certification Courses

          Excel Course certificate
        • Excel VBA All in One Bundle

          Excel-VBA-Certification-Course
        • Excel Data Analysis Course

          Excel-Data-Analysis-Course
        • VBA Macros Course

          VBA-Training-Course
        • Others

          • Basic Excel Training
          • Advanced Excel Course
          • Tableau Certification Course
          • Excel for Finance Course

          • Excel for Marketers Course
          • Excel for HR Managers
          • Excel for Power Users
          • View All
  • Excel VBA All in One Bundle
  • Login

VBA Operators

Home » VBA » VBA Logical Functions » VBA Operators

By Tejswini Bhosale Leave a Comment

vba-operators

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.

vba operators list

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.

Popular Course in this category
Cyber Monday Sale
VBA Training (3 Courses, 12+ Projects) 3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
4.6 (247 ratings)
Course Price

View Course

Related Courses
You can download this VBA Operators Excel Template here – VBA Operators Excel Template

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

vba operators example 1.1

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

vba operators example 1.2

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

vba operators example 2.1

And the result will be –

vba operators example 2.2

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

vba operators example 3.1

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

example 3.2

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

example 3.3

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

example 4.1

This returns FALSE because 25 is not less than 20.

example 4.2

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

example 5.1

You will get the following output.

example 5.2

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
0 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>

Filed Under: VBA, VBA Logical Functions

Reader Interactions
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer
COMPANY
About
Reviews
Blog
Contact
Privacy
Terms of Service
FREE COURSES
Free Finance Online Course
Free Accounting Online Course
Free Online Excel Course
Free VBA Course
Free Investment Banking Course
Free Financial Modeling Course
Free Ratio Analysis Course

CERTIFICATION COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Business Valuation Course
Equity Research Course
CFA Level 1 Course
CFA Level 2 Course
Venture Capital Course
Microsoft Excel Course
VBA Macros Course
Accounting Course
Advanced Excel Course
Fixed Income Course
RESOURCES
Investment Banking
Financial Modeling
Equity Research
Private Equity
Excel
Books
Certifications
Accounting
Asset Management
Risk Management

Copyright © 2019. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.
WallStreetMojo

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Free Investment Banking Course

IB Excel Templates, Accounting, Valuation, Financial Modeling, Video Tutorials

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.

* Please provide your correct email id. Login details for this Free course will be emailed to you

WallStreetMojo

Download VBA Operators Excel Template

By continuing above step, you agree to our Terms of Use and Privacy Policy.

Limited Period Offer - VBA Training Course (6 courses, 35+ hours video) View More