The VBA SGN Function

Related Function:


The VBA Sgn function returns an integer (+1, 0 or -1), representing the arithmetic sign of a supplied number.

The syntax of the function is:

Sgn( Number )

Where the Number argument is the number that you want the arithmetic sign of.

VBA Sgn Function Examples

' Return the arithmetic sign of the numbers 5, 0 and -0.1
Dim int1 As Integer
Dim int2 As Integer
Dim int3 As Integer
int1 = Sgn( 5 )
int2 = Sgn( 0 )
int3 = Sgn( -0.1 )
' Now, int1 = 1, int2 = 0 and int3 = -1

In the above VBA code:

VBA Sgn Function Error

If the Sgn 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