VBA Operators and Precedence (Ready Reference 3.0)

This article describes the operators available in VBA, their order of precedence in calculation and the types of data returned by each operator in an expression.

Operator evaluation proceeds from left to right in an expression, except that evaluation of operators with a higher precedence to the right of the current operator occurs before those lower precedence operators to their left.

If you are ever uncertain of how Excel approaches a calculation, you can use the Immediate Window in the VBA Editor to test expressions.  Note that unless type characters are appended to numbers or values are expressly decimal, the Immediate Window will assume integer values.

The table below sets out all the operators in VBA with their relative precedence in calculation.  It shows the relative level of precedence of each set of operators.  Operators listed with the same precedence are evaluated in the order in which they appear in an expression, as their precedence is equivalent.

PrecedenceOperatorResult TypeDescription
1( )VariesGrouping operators
Placing parentheses around any part of an expression ensures that the parts of the expression inside the parentheses are evaluated prior to operators either side. The order of precedence within the parentheses is resolved on the basis of the precedence listed here. The result type of an expression in parentheses is the result type of the lowest order operator within the parentheses.
2-NumericUnary negation operator
Takes one value only on its right. Returns the result of sign-switching the value on the right of the operator.
3^NumericExponentiation operator
Returns the result of raising the value on the left of the operator to the power of the value on the right of the operator.
4*NumericMultiplication operator
Returns the product that is the result of multiplying the value on the left of the operator by the value on the right of the operator.
4/NumericDivision operator
Returns the dividend that is the result of dividing the value on the left of the operator by the value on the right of the operator.
5\Integer
Long
LongLong
Integer Division operator
Returns the integer dividend that is the result of dividing the integer value of the value on the left of the operator by the integer value of the value on the right of the operator.
6ModInteger
Long
LongLong
Integer Modulo operator
Returns the integer dividend that is the result of dividing the integer value of the value on the left of the operator by the integer value of the value on the right of the operator.
7+NumericAddition operator
Returns the sum that is the result of adding the value on the right of the operator to the value on the left of the operator.
7-NumericSubtraction operator
Returns the difference that is the result of subtracting the value on the right of the operator from the value on the left of the operator.
8&StringString Concatenation operator
Returns the string result formed by appending the characters from the value to the right of the operator to the end of the string of characters from the value to the left of the operator.
9=BooleanEquality operator
Returns the result of comparing the value on the left of the operator to the value on the right of the operator.
9<>BooleanInequality operator
Returns the result of comparing the value on the left of the operator to the value on the right of the operator.
9<BooleanLess Than operator
Returns the result of comparing the value on the left of the operator to the value on the right of the operator.
9<=BooleanLess Than or Equal to operator
Returns the result of comparing the value on the left of the operator to the value on the right of the operator.
9>BooleanGreater Than operator
Returns the result of comparing the value on the left of the operator to the value on the right of the operator.
9>=BooleanGreater Than or Equal to operator
Returns the result of comparing the value on the left of the operator to the value on the right of the operator.
10LikeBooleanLike operator
Returns the result of comparing the value on the left of the operator to string pattern given in the value on the right of the operator. Returns True if the patterns match, otherwise returns False.
11IsBooleanIs operator
Returns the result of comparing the object reference on the left of the operator to the object reference on the right of the operator. Returns True if both references are to the same object, otherwise returns False.
12NotBooleanLogical Not operator
Returns the logical not of he value on its right. Returns True if the value on the right is false, otherwise returns True.
13AndBoolean
Numeric
Logical And operator
Returns the logical And derived by bitwise comparison of the value on the left and the value on the right. In the result, the bits on will be those that corresponde to the ones that are on in both values.
14OrBoolean
Numeric†
Logical Or operator
Returns the logical Or derived by bitwise comparison of the value on the left and the value on the right. In the result the bits on will be those that corresponde to the ones that are on in either of the values.
15XorBoolean
Numeric†
Logical Exclusive Or operator
Returns the logical Exclusive Or derived by bitwise comparison of the value on the left and the value on the right. In the result the bits on will be those that correspond to those that are on in only one of the vaues.
16EqvBoolean
Numeric†
Logical Equivalence operator
Returns the logical Equivalence derived by bitwise comparison of the value on the left and the value on the right. In the result the bits on will be those that correspond to that are either both on or both off in both values.
17ImpBoolean
Numeric†
Logical Implication Or operator
Returns the logical Exclusive Or derived by bitwise comparison of the value on the left and the value on the right. In the result all bits will be on except those that correspond to the onse where the bit is on in the value on the left and off in the value on the right.

The table above can be sorted by operator, precedence and filtered by data type returned.

† Numeric return values may include Interger, Long, LongLong, Single, Double, Decimal, Currency or Date, depending upon the types of values passed to an expression, and the way in which unmateched data types are cast.

Clarkson ITT builds & delivers
expert training, in classrooms
& online, for professionals in
finance, funds management &
accounting - developing their
skills in modelling and analysis.

Contact

+61 2 9871 0399
PO Box 104
West Pennant Hills NSW 2125
Australia
Clarkson ITT Company page
@ClarksonITT

Please publish modules in offcanvas position.