VBA Operators and Precedence

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.  The grouping symbols (left and right parentheses) override the default calculation order in that any expression inside the grouping symbols must be evaluated before the result is passed to the operators outside.

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 Visual Basic for Applications (VBA) with their relative precedence in calculation (shown as a precedence level - higher number has higher precedence).  Operators listed with the same precedence level are evaluated in the order in which they appear in an expression, as their precedence is equivalent.

PrecedenceOperatorResult TypeDescription
16-NumericUnary negation operator
Takes one value only on its right. Returns the result of sign-switching the value on the right of the operator.
15^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.
14*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.
14/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.
13\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.
12ModInteger
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.
11+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.
11-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.
10&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.
8LikeBooleanLike 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.
7IsBooleanIs 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.
6NotBooleanLogical 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.
5AndBoolean
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.
4OrBoolean
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.
3XorBoolean
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.
2EqvBoolean
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.
1ImpBoolean
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.