Operators are important in writing Excel VBA program code. They are used to calculate values, perform certain operations, make comparisons and more. The operators can be divided into three main categories:
Arithmetic operators are used to perform mathematical operations in Excel VBA.
MsgBox is a built-in function of excel VBA that displays a message. We shall learn more about functions in next lesson. Note that MsgBox 1+"VBA" will produce a type mismatch error whereas MsgBox 1&"VBA" will not result in an error, it gives a concatenated string 1VBA.
We shall engage the usage of arithmetic operators in Excel VBA code writing in future lessons.
4.2 Comparison Operators
Comparison operators are often used in writing code that require decisions making. For example,
If mark>50 then
MsgBox "Pass"
Else
MsgBox "Fail"
Endif
We shall learn more about writing decision making code in future lessons.
comparison operators are shown in Table 4.2.
* For letters, the hierarchy is A>B>C>..........>Z
Therefore MsgBox A>B returns true
Logical operators are also used in writing decision making codes by comparing values or expressions.