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

How To Remove Special Characters in Excel
remove special character2

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
insert commetns in protected workshee3

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
convert text to upper cases1

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)
hide every other row1

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

How to Disable the Save As Prompt in Excel
disable save as prompt1

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel
count cells that contain even numbers5

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells Are Not Blank or Empty in Excel
count non blank nonempty cells5

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Less Than a Specific Value in Excel
count cells lessr than5

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

How to Count Cells Greater Than a Specific Value in Excel
count cells greater than 5

This post will guide you how to count the number of cells greater than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are greater than a specific ...

How to Remove All Extra Spaces and Keep Only One Between Words in Excel
How to Remove All Extra Spaces and Keep Only One Between Words 7

Sometimes when copying something from other type files to excel, there might be two or more spaces display between words. Extra spaces between words are frequently to be seen in excel, and this behavior is very annoying. If we want ...

Sidebar