Used to raise a number to the power of an exponent.
The ^ operator syntax has these parts:
|result||Required; any numeric variable.|
|number||Required; any numeric expression.|
|exponent||Required; any numeric expression.|
A number can be negative only if exponent is an integer value. When more than one exponentiation is performed in a single expression, the ^ operator is evaluated as it is encountered from left to right.
This example uses the ^ operator to raise a number to the power of an exponent.
Dim MyValue MyValue = 2 ^ 2 ' Returns 4. MyValue = 3 ^ 3 ^ 3 ' Returns 19683. MyValue = (-5) ^ 3 ' Returns -125.
For 64-bit users: Because the caret operator is used to create Long Long data types in a 64-bit environment, the VBA IDE may not interpret this operator correctly. To ensure proper interpretation, add a space character immediately before the caret as shown.
x=y^2 ' Will generate "expected )" from VBA IDE. x=y ^2 ' Will be interpreted as x equals y squared.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.