Excel VBA Operators

This post will  describe the VBA operators in the MS Excel. There are 4 kinds of operators in VBA as bellow:

  • Arithmetic operators
  • Comparison operators
  • Concatenation operators
  • Logical operators

VBA Arithmetic Operators

Arithmetic operators used to perform the basic mathematical operations such as: addition, subtraction multiplication, or division and so on. Let see the below table and contains all operators in Excel VBA.

Arithmetic operator Description Example
+ (plus sign) Addition 3+3
– (minus sign) Subtraction
Negation
3–1
–1
* (asterisk) Multiplication 3*3
/ (forward slash) Division 3/3
% (percent sign) Percent 20%
^ (caret) Exponentiation 3^2

VBA Comparison Operators

The comparison operators used to compare two values and the result will be returned, such as: True or False.

The following comparison operators can be used in the VBA:

Comparison operator Description Example(A1=10, B1=15)
= (equal sign) Equal to A1=B1 is False.
> (greater than sign) Greater than A1>B1 is False
< (less than sign) Less than A1<B1 is True
>= (greater than or equal to sign) Greater than or equal to A1>=B1 is False
<= (less than or equal to sign) Less than or equal to A1<=B1 is True
<> (not equal to sign) Not equal to A1<>B1 is True

VBA Concatenation Operators

The concatenation operators use to join two or more text strings to produce one continuous text string. Or  adds two values as variable, and those two values are numeric.

Text operator Description Example(A1=”excel”, B1=”how”)
& (ampersand) Connects, or concatenates, two values to produce one continuous text value A1&B1 is “excelhow”

 

Text operator Description Example(A1=”excel”, B1=”how” A2=10 B2 =15)
+ If the values are numeric and it will perform the addition operation. Or if the values are two text string, then it will concatenate those tow text string. A1+B1 will give “excelhow”

A2 +B2 will give 25

 VBA Logical Operators

The following Three logical operators are the most useful in the Excel VBA:

Logical operator Description Example (A1=15, B1=0)
AND Logical AND operator. If both the conditions are True, then the Expression is true. A1>0 AND B1<>0 is False.
OR Logical OR Operator. If any of the two conditions are True, then the condition is true. A1<>0 OR B1<>0 is true.
NOT Logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make false. NOT(A1<>0 OR B1<>0) is false.
Related Posts

VBA Macro For VLOOKUP From Another Sheet

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Remove Special Characters in Excel

This post will show you how to remove special characters from text strings in Excel. And I am going to introduce two ways to remove special characters (@&)#%$) from a string in Excel. Removing Special Characters using Power Query If ...

How To Insert Comments in Protected Worksheet in Excel

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

Comments

So empty here ... leave a comment!

Leave a Reply

Sidebar