The VBA ABS Function

Related Function:
VBA Sgn

Description

The VBA Abs function returns the absolute value of a number.

The syntax of the function is:

Abs( Number )

Where the Number argument is the number that you want the absolute value of.


VBA Abs Function Examples

' Return the absolute value of the numbers 5 and -0.9
Dim val1 As Double
Dim val2 As Double
val1 = Abs( 5 )
val2 = Abs( -0.9 )
' Now, val1 = 5 and val2 = 0.9

In the above VBA code:


VBA Abs Function Error

If the Abs function is supplied with a value that cannot be interpreted as a number, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box