The VBA Abs function returns the absolute value of a number.
The syntax of the function is:
Where the Number argument is the number that you want the absolute value of.
' Return the absolute value of the numbers 5 and -0.9
Dim val1 As Double
Dim val2 As Double
val1 = Abs( 5 )
' Now, val1 = 5 and val2 = 0.9
val2 = Abs( -0.9 ) |
In the above VBA code:
If the Abs function is supplied with a value that cannot be interpreted as a number, it will return the error: