The VBA SGN function is listed under the math category of VBA functions. When you use it in a VBA code, it returns the arithmetic sign of an integer. In simple words, it returns +1 for a positive number, -1 for a negative number, and a 0 for the zero.
- Number: An integer to specify the number that you want the arithmetic sign of.
To practically understand how to use VBA SGN function, you need to go through the below example where we have written a vba code by using it:
Sub example_SGN() Range("B1").Value = Sgn(Range("A1")) End Sub
In the above code, we have used the SGN to get the arithmetic sign and it has returned 1 as we have a positive number in cell A1.
- If the value specified is a value other than a number or a number that can’t be recognized as a number, VBA will return the run-time 13 error.