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:
Where the Number argument is the number that you want the arithmetic sign of.
' 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 )' Now, int1 = 1, int2 = 0 and int3 = -1
int2 = Sgn( 0 )
int3 = Sgn( -0.1 )
In the above VBA code:
If the Sgn function is supplied with a value that cannot be interpreted as a number, it will return the error: