Operators in VBA Excel

Last Updated on January 11, 2023 by token

Types of operators in Excel VBA

In our scripts we will use both arithmetic expressions and logical expressions. For this purpose, we will be able to use operators in Excel VBA, we can put them into 3 groups:

• arithmetic
• logical
• comparison

VBA operators: arithmetic

Arithmetic operators serve as the name suggests the implementation of operations in math. When creating a procedure containing mathematical operations, it may also be necessary to use parentheses. We write them in the standard way: “()”.

As you can see, the “+” operator can also be used to connect strings to each other. For the same purpose, you can also use the operator: “&”. The example is described below.

```'OfficeInside.Org
Sub SumOperators()
MsgBox "string_1 " & "string_2"
MsgBox "string_1 " + "string_2"
End Sub```

If you want to use the minority and majority operators in relation to letters, the procedure will return true or false depending on which place the given letter is in the alphabet.

```'OfficeInside.Org
Sub LogOperators()
MsgBox "A" < "B" 'returns True
MsgBox "A" = "B" 'returns False
End Sub```

VBA operators: comparison

Comparison operators are used to compare selected data. Their description and application example are below. Using the following construction, the result will be True or False each time.

VBA operators: logical

The basis for a good script is correctly logic. We will use logical operators to save it.

Tasks (You can save the result in a comment)

1. Record any action using all the arithmetic operators at the same time. The operation should give in result 100.

More examples of Excel VBA basics can be found in the Excel VBA Course section and  Excel VBA How To section. If you have any questions about this chapter, you can post them on the forum without logging in.