9/27/24, 1:39 AM VBA - Operators
VBA - Operators
An Operator can be defined using a simple expression - 4 + 5 is equal to 9. Here, 4 and 5
are called operands and + is called operator. VBA supports following types of operators
−
Arithmetic Operators
Comparison Operators
Logical (or Relational) Operators
Concatenation Operators
The Arithmatic Operators
Following arithmetic operators are supported by VBA.
Assume variable A holds 5 and variable B holds 10, then −
Show Examples
Operator Description Example
+ Adds the two operands A + B will give 15
- Subtracts the second operand from the first A - B will give -5
* Multiplies both the operands A * B will give 50
/ Divides the numerator by the denominator B / A will give 2
Modulus operator and the remainder after an integer
% B % A will give 0
division
B ^ A will give
^ Exponentiation operator
100000
The Comparison Operators
There are following comparison operators supported by VBA.
Assume variable A holds 10 and variable B holds 20, then −
Show Examples
https://www.tutorialspoint.com/vba/vba_operators.htm 1/3
9/27/24, 1:39 AM VBA - Operators
Operator Description Example
Checks if the value of the two operands are equal or
= (A = B) is False.
not. If yes, then the condition is true.
Checks if the value of the two operands are equal or
<> not. If the values are not equal, then the condition is (A <> B) is True.
true.
Checks if the value of the left operand is greater than
> the value of the right operand. If yes, then the (A > B) is False.
condition is true.
Checks if the value of the left operand is less than the
< value of the right operand. If yes, then the condition (A < B) is True.
is true.
Checks if the value of the left operand is greater than
>= or equal to the value of the right operand. If yes, then (A >= B) is False.
the condition is true.
Checks if the value of the left operand is less than or
<= equal to the value of the right operand. If yes, then (A <= B) is True.
the condition is true.
Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.
The Logical Operators
Following logical operators are supported by VBA.
Assume variable A holds 10 and variable B holds 0, then −
Show Examples
Operator Description Example
Called Logical AND operator. If both the a<>0 AND b<>0 is
AND
conditions are True, then the Expression is true. False.
Called Logical OR Operator. If any of the two
OR a<>0 OR b<>0 is true.
conditions are True, then the condition is true.
Called Logical NOT Operator. Used to reverse the
NOT(a<>0 OR b<>0) is
NOT logical state of its operand. If a condition is true,
false.
then Logical NOT operator will make false.
https://www.tutorialspoint.com/vba/vba_operators.htm 2/3
9/27/24, 1:39 AM VBA - Operators
Called Logical Exclusion. It is the combination of
NOT and OR Operator. If one, and only one, of (a<>0 XOR b<>0) is
XOR
the expressions evaluates to be True, the result true.
is True.
The Concatenation Operators
Following Concatenation operators are supported by VBA.
Assume variable A holds 5 and variable B holds 10 then −
Show Examples
Operator Description Example
+ Adds two Values as Variable. Values are Numeric A + B will give 15
& Concatenates two Values A & B will give 510
Assume variable A = "Microsoft" and variable B = "VBScript", then −
Operator Description Example
+ Concatenates two Values A + B will give MicrosoftVBScript
& Concatenates two Values A & B will give MicrosoftVBScript
Note − Concatenation Operators can be used for both numbers and strings. The output
depends on the context, if the variables hold numeric value or string value.
https://www.tutorialspoint.com/vba/vba_operators.htm 3/3