An Interactive Learning Tool

Proud to be a Teacher


Operators

An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in all language program to operate on data and variables. operators can be classified as:
1. Arithmetic Operators
2. Comparison
3. Logical Operators

Arithmetic Operators:

Arithmetic operators are used to perform mathematical operations in Excel VBA. All the basic arithmetic operations can be carried out in VBA. All the operators have almost the same meaning as in other languages.
Symbal Operator Example Result
Addition + 2+2 4
Subtraction - 4-2 2
Division / 8/2 4
Multiplication * 3/2 6
Modules % 20% 10 2

Comparison Operators:

Comparison Operators are often used to write code to do comparison between numerical and non-numerical statement and results as True or False.
Example:
If Sales > 5000 then
MsgBox "Eligible for Bonus"
Else
MsgBox "No Bonus"
These decision making operators can be used in various statements.

Common Comparison Operators:

Symbal Name Example
= Equal to 2 = 2
< Lesser than 3 < 2
> Greater than 4 > 2
<> Not Equal to 9 <> 7
=> Equal to or greater than 5 => 4 OR 5 => 5
<= Lesser than or equal to 4 <= 5 OR 5 <= 5

Logical Operators

Logical operators are also used in writing decision making codes by comparing values or expressions.

Logical Operators

Operator Meaning Example
And Logical Conjunction If A>=80 And B<101 thenGrade="A"
Or Logical Disjunction If income>5000 or car>2 thenStatus="Rich"
Not Logical negation MsgBox Not (3 > 4)returns true
Xor Similar to Or, except that it returns False if both camparison values are true MsgBox 4 > 3 Xor 5 >2 returns false

Relational Operators :

Often it is required to compare the relationship between operands and bring out a decision and program accordingly. This is when the relational operator come into picture. Following are the relational operators.

Relational OperatorsDescription
<Less than
<=Less than or equal to
>Greater than
==equal to
<>Not equal to
It is required to compare the Sales of 2 Salesmen, salary of 2 persons, we can compare them using relational operators. A simple relational expression contains only one relational operator


Terms of use Website Policy Contact us
© Copyrights ExcelYourVBA.com 2020