- operator
Used to find the difference between two numbers or to indicate the negative value of a numeric expression.
Syntax
Syntax 1
result = number1 - number2
Syntax 2
-
number
The -
operator syntax has these parts:
Part | Description |
---|---|
result | Required; any numeric variable. |
number | Required; any numeric expression. |
number1 | Required; any numeric expression. |
number2 | Required; any numeric expression. |
Remarks
In Syntax 1, the -
operator is the arithmetic subtraction operator used to find the difference between two numbers. In Syntax 2, the -
operator is used as the unary negation operator to indicate the negative value of an expression.
The data type of result is usually the same as that of the most precise expression. The order of precision, from least to most precise, is Byte, Integer, Long, Single, Double, Currency, and Decimal. The following are exceptions to this order:
If | Then result is |
---|---|
Subtraction involves a Single and a Long | Converted to a Double. |
The data type of result is a Long, Single, or Date variant that overflows its legal range | Converted to a Variant containing a Double. |
The data type of result is a Byte variant that overflows its legal range | Converted to an Integer variant. |
The data type of result is an Integer variant that overflows its legal range | Converted to a Long variant. |
Subtraction involves a Date and any other data type | A Date. |
Subtraction involves two Date expressions | A Double. |
If one or both expressions are Null expressions, result is Null. If an expression is Empty, it is treated as 0.
Note
The order of precision used by addition and subtraction is not the same as the order of precision used by multiplication.
Example
This example uses the - operator to calculate the difference between two numbers.
Dim MyResult
MyResult = 4 - 2 ' Returns 2.
MyResult = 459.35 - 334.90 ' Returns 124.45.
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 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기