**Introduction to operation**

An operator is a character that acts on two operands to give an output.

For example, for example..,

Consider the following expressions:

- Â A + B = C

Here

A, B and C are called operands

Ð˜

+ and = are called operators.

2. C > D

Here

C and D are called operands

Ð˜

is called an operator.

**Types of operators**

Operators are divided into four types.

- arithmetic operators
- Equation operators
- Relational or logical operators
- Concentration Operator

Let’s take a look at each of these options – I’ll give you descriptions and many examples along the way.

**Arithmetic operators**

These operators are mathematical symbols used in calculations. Here is the list of arithmetic operators supported by VBA.

no | Operator | Description | Example |

1 | + | Displays the addition of two operands | 4 + 5 equals 9 |

2 | â€“ | Subtracts the second operand from the first operand | 8 – 5 results in 3 |

3 | * | Multiplies the two opera scenes on the sides | 4 * 6 results in 24 |

4 | / | Divide the numerator by the denominator. | 9 / 3 gives 3 |

5 | Mod | Module operator. This is the net book value after the demerger operation. | 10 % 3 gives a memo value of 1 after division. |

6 | ^ | Exposure Operator | 10 ^ 3 results in 1000 |

**Example programmes**

**A program with all the above operators**

Sub arith_oper_demo()

Report variables

Dim a, b, c

Assigning values to variables

a = 6

b = 7

Try different calculations and get

‘ Addition operator

c = a + b

Debug.Print Addition: & c

Deduction operator (positive and negative results)

c = b – subtraction

Debug.Print: & c

c = a – b

Subtract from debug printout: & c

Multiplication operator

c = a * b

Debugging, printing Multiplication: & c

division operator

c = a / b

division Debug.Print: & c

Module Operator

c = a Mod b

Debug and print module: & c

Exponentiation

c = a ^ b

Debug.Print Exponentiation: & c

Last Subsection

alt=Using all basic operators as specified in data-orig-width=960 data-orig-height=540 data-ezsrc=http://server.digimetriq.com/wp-content/uploads/2021/02/Your-Guide-to-Using-Operators-in-VBA.png data-ez= />.

alt=pin it! data-ezsrc=/utilcave_com/social/pin_it.png />

alt=Facebook-ezsrc=/utilcave_com/social/fb_share.png />

**Calculation of the volume of a sphere**

This program takes the radius value as user input, calculates the volume and displays it in the message.

Sub vol_sp()

Variable explanation

Dim Pi, r, vol

Assign values to variables

Pi = 3.14 ‘or (22/7)

r = InputBox( enter the radius of the sphere )

Calculation

ob = (4 / 3) * Pi * (r ^ 3)

Display the calculated volume

MsgBox Volume of the sphere with radius & r & is & full & .

Last Subsection

alt=Volume of a sphere of radius 3 is 113.04 data-orig-width=471 data-orig-height=225 data-ezsrc=http://server.digimetriq.com/wp-content/uploads/2021/02/1614204878_707_Your-Guide-to-Using-Operators-in-VBA.png data-ez= />

alt=pin it! data-ezsrc=/utilcave_com/social/pin_it.png />

alt=Facebook-ezsrc=/utilcave_com/social/fb_share.png />

**Comparative operators**

These are characters used to compare values. Here is a list of comparison operators provided by VBA that are used for validation in programming.

W/H. | Operator | Description | Example | Output |

1 | = | Idem | If x = z, then | Returns true if the values of the operands ( x and y ) are equal, otherwise it returns false. |

2 | < | Less than | If x < z Then | If the value of x is less than the value of z, True is returned. Otherwise, he sends it back wrong. |

3 | > | More than | If x > z, then | If the value of x is greater than the value of z, True is returned. Otherwise, he sends it back wrong. |

4 | <> | Not right away. | If x <> z Then | If the x value does not match the z value, True is returned. Otherwise, he sends it back wrong. |

5 | <= | Less than or equal to | If x <= z Then | If the x value is less than or equal to the z value, True is returned. Otherwise, he sends it back wrong. |

6 | >= | Greater than or equal to | If x >= z Then | If the x value is greater than or equal to the z value, True is returned. Otherwise, he sends it back wrong. |

**Example programmes**

**A program that compares the ages of two people**

Sub compare_demo()

Declare variables

Dim fath_age, uncl_age

Assign the values

fath_age = InputBox(Enter your father’s age ðŸ™‚

uncl_age = InputBox(Enter your uncle’s age ðŸ™‚

This compares the ages of your uncle and father

If fath_age > uncl_age Then

MsgBox Your father is older than your uncle.

ElseIf fath_age = uncl_age Then

MsgBox Your father and uncle are the same age.

Else

MsgBox Your uncle is older than your father.

Ends when

Last Subsection

**Pre-departure baggage weight check programme**

Sub compare_weigh()

Explain variables

Dim allwd_wt, curr_wt

Assign values in kg

allwd_wt = 10

curr_wt = InputBox( Enter the weight of your baggage)

Check if the weight is included in

If curr_wt <= allwd_wt Then

flag = 1

Otherwise

flag = 0

End If

display the appropriate message on the passenger display

If Flag = 1, then

MsgBox The weight of your luggage is within the allowed limit. No further action is required.

Else

MsgBox The weight of your baggage exceeds the allowed limit. Bring some luggage and check it in before you board.

End if

End Sub

The equation in the program above can also be written with the operator more than instead of the operator less than or equal to.

If curr_wt > allwd_wt, then

Flag = 0

Otherwise

Flag = 1

End If

**Relational or logical operators**

If multiple conditions need to be evaluated, you can use logical operators to see how many different conditions are met.

For example:

Men must be 60 or older to be seniors.

However, women older than 58 are considered elderly. Year of life.

If the program requires a written form to verify eligibility, we must check gender and age to determine whether or not someone is a senior. That’s where the logical operators come in.

The following code snippet uses the two logical operators OR and AND.

If age >= 60 or ( age >= 58 and gender = female ), then

Debug.Print The person is retired.

Other

Debugging.Print Person is not retired.

The end is.

Below are six logical operators that VBA provides.

no | Operator | Description | Example | Exit and explanation |

1 | Ð˜ | This is the logical operator AND. It will come back when conditions on both sides become real again. | Len( ABC) = 3 and 5 + 3 = 3 | The first condition is true and the second is false. According to the rule of this operator, the final answer is false, even if a condition is returned false. |

2 | OR | This is the logical operator AND. It becomes true again when one of the conditions on either side becomes true again. | Len( ABC) = 3 OR (5 + 3) = 3 | The first condition is true and the second is false. The rule of this operator is that at least one condition must be true for the final answer to be true. Therefore, the end result is TRUE. |

3 | PAS | This is called the logical operator NOT. It changes the logical state of its operand. If the condition is true, the logical operator does NOT return the opposite value (in this case, the opposite value is false). | NOT(Len( ABC) = 3 OR (5 + 3) = 4) | The first condition is true and the second is false. The rule of this operator is that at least one condition must be true for the final answer to be true. So the end result is correct. The operator NOT cancels the true answer in FALSE. |

4 | XOR | The XOR operator is called a logical exception. This is a combination of the operators NOT and OR. If only one of the expressions is calculated as true, the result is true. If none of the conditions are true or if more than one condition is true, the XOR operator returns false. | Len( ABC) = 3 XOR (5 + 3) = 3 | Only one of these conditions is met. Therefore, the end result is TRUE. |

5 | IS | This Boolean operator compares two object variables and returns true only if they store the same object. | Workbooks. Worksheets (ABCs) are workbooks. Sheets (DEF). | The two worksheets are different and therefore the result will be incorrect. |

6 | HOW | This Boolean operator LIKE allows you to compare two strings to get an inexact match. It can check patterns or strings within another string. | string1= I love my country , if string1 LIKE *love*, then |
The condition checks that the string starts with a few characters, contains the word love, and ends with a few characters again. Since these conditions are met, the condition is true. |

**Example programmes**

**Use of a similar operator**

If Tamil Nadu is in India like Tamil*, then

Debug.Print String starts with expected text

Otherwise

Debug.Print String does not start with expected text

End If

Output

The line begins with the expected text.

**Use of the operator NOT**

check if the key exists in the dictionary objectIf Not( MyDict.Exists(Class I) ) ThenDebug.Print Does not existEnd if

**Using the XOR**operator

Sub xor_demo()

Explanation of variables

Dim amt, points

Assign values to the variables

amt = 2000

points = 400

XOR demo – only one condition is met

If number > 200 Xor points > 500 Then

Debug.print (You win the voucher_1)

End if

XOR demo – both conditions are met

If amt > 1500 Xor points > 200 Then

Debug.Print (You win coupon_2)

End If

If the number of points XOR > 6500 Xor > 500 Then

Debug.Print (You win a coupon_3)

End if

Last Subsection

alt=Example XOR data-orig-width=960 data-orig-height=540 data-ezsrc=http://server.digimetriq.com/wp-content/uploads/2021/02/1614204878_213_Your-Guide-to-Using-Operators-in-VBA.png data-ez= />

alt=pin it! data-ezsrc=/utilcave_com/social/pin_it.png />

alt=Facebook-ezsrc=/utilcave_com/social/fb_share.png />

**Concentration Operator**

These are operators that can merge two expressions.

Message: If both expressions are numbers, they are summed when the + sign is used.

VBA provides the following two operators for concatenation.

no | Operator | Description |

1 | + | Concentrates two values if one or both is a string. If both are numeric values, they are added together. |

2 | & | Joins two expressions together (connects them). |

**Program example**

Sub concat_demo()

Variable return

Dim str1, str2

Dim num1, num2

Assigning values to variables

str1 = Want to

str2 = Eat cake

Number1 = 32

Number2 = 5

with concatenation operator +

Debug.Print str1 + str2

Debug.Print num1 + num2

with concatenation operator &

Debug.Print str1 & str2

Debug.Print num1 & num2

Last Subsection

alt=Want some cake? data-orig-width=1024 data-orig-height=576 data-ezsrc=http://server.digimetriq.com/wp-content/uploads/2021/02/1614204879_498_Your-Guide-to-Using-Operators-in-VBA.png data-ez= />

alt=pin it! data-ezsrc=/utilcave_com/social/pin_it.png />

alt=Facebook-ezsrc=/utilcave_com/social/fb_share.png />

**Completion**

These four types of operators are essential to build the logic and redirect the control flow in a program. Many of us stick to the basic operators and can’t remember everything in VBA.

You have to be. B. only do something if a key-value pair is missing from the dictionary object. In this case, we use the keyword Exists to verify existence. However, if this keyword is used in combination with the operator NOT, the number of code lines can be reduced (another code block can be avoided). Depending on the situation, optimal use should be made of these operators.

*Marked with: Equation operators, Concentration, Commentary, Logic, Logic operators, Math, NOT, Operand, Operator, Relative operators, XOR*

#### Related Tags:

**types of operators in visual basic**,**visual basic operators in hindi**,**vb net integer operators**,**divide operator in vb**,**visual basic logical and**,**in visual basic “<=” is ________ operator**,**symbol in vba**,**vba backslash operator**,**vba question mark operator**,**arithmetic operators in vba**,**what is the output of 5&10&15 in vba**,**what is the result in vba of expression-10^5**,**excel vba not equal to blank**,**not equal vb**,**excel vba**,**vba logical operators**,**vba excel comparison**,**div visual basic**,**what is 11 mod 7**,**vba mod function**,**what is -11 mod 7**,**excel mod function**,**visual basic commands pdf**,**visual basic commands excel**,**visual basic command button code**,**visual basic command words**,**visual basic functions**,**visual basic commands dim**,**Privacy settings**,**How Search works**,**vba operators list**,**arithmetic operators in visual basic**,**vba comparison operators**,**operators in visual basic 6.0 pdf**,**conditional operators in visual basic**