VBA Mathematical Operators


Example

Listed in order of precedence:

TokenName              Description
^ExponentiationReturn the result of raising the left-hand operand to the power of the right-hand operand. Note that the value returned by exponentiation is always a Double, regardless of the value types being divided. Any coercion of the result into a variable type takes place after the calculation is performed.
/Division1Returns the result of dividing the left-hand operand by the right-hand operand. Note that the value returned by division is always a Double, regardless of the value types being divided. Any coercion of the result into a variable type takes place after the calculation is performed.
*Multiplication1Returns the product of 2 operands.
\Integer DivisionReturns the integer result of dividing the left-hand operand by the right-hand operand after rounding both sides with .5 rounding down. Any remainder of the division is ignored. If the right-hand operand (the divisor) is 0, a Run-time error 11: Division by zero will result. Note that this is after all rounding is performed - expressions such as 3 \ 0.4 will also result in a division by zero error.
ModModuloReturns the integer remainder of dividing the left-hand operand by the right-hand operand. The operand on each side is rounded to an integer before the division, with .5 rounding down. For example, both 8.6 Mod 3 and 12 Mod 2.6 result in 0. If the right-hand operand (the divisor) is 0, a Run-time error 11: Division by zero will result. Note that this is after all rounding is performed - expressions such as 3 Mod 0.4 will also result in a division by zero error.
-Subtraction2Returns the result of subtracting the right-hand operand from the left-hand operand.
+Addition2Returns the sum of 2 operands. Note that this token also treated as a concatenation operator when it is applied to a String. See Concatenation Operators.

1 Multiplication and division are treated as having the same precedence.

2 Addition and subtraction are treated as having the same precedence.