^ operator
Used to raise a number to the power of an exponent.
Syntax
result=number^exponent
The ^ operator syntax has these parts:
Part | Description |
---|---|
result | Required; any numeric variable. |
number | Required; any numeric expression. |
exponent | Required; any numeric expression. |
Remarks
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.
Usually, the data type of result is a Double or a Variant containing a Double. However, if either number or exponent is a Null expression, result is Null.
Example
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.
Note
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.
See also
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.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기