Be the first user to complete this post

  • 0
Add to List

Excel-VBA/Formula : Math Functions – SGN/SIGN()

Description: The SGN()/SIGN function in MS excel returns the Sign of a number

NOTE: This function has different names, when used as VBA function it is SGN() and when used as Excel formula it is SIGN().

Format:

As VBA Function : SGN(number)

As Excel Formula : SIGN(number)

Arguments:

  • Number
    • Mandatory
    • Type: Number
    • Number to get the sign for

Cases:

  1. Number greater than 0 , SGN/SIGN will return 1
  2. Number = 0 , SGN/SIGN will return 0
  3. Number less than 0 , SGN/SIGN will return -1

VBA Example:

Function getSGN()
    Dim val1
    Dim val2
    Dim val3
    val1 = 3.33
    val2 = 0
    val3 = -9
    strResult = "The SGN of number " & val1 & " is " & Sgn(val1) & vbCrLf
    strResult = strResult & "The SGN of number " & val2 & " is " & Sgn(val2) & vbCrLf
    strResult = strResult & "The SGN of number " & val3 & " is " & Sgn(val3)
    MsgBox strResult
End Function

VBA - SGN()
VBA - SGN()

Formula Example :

SIGN - Formula
SIGN - Formula