편집

다음을 통해 공유


^ 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.