Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

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

Descrip­tion: The SGN()/SIGN func­tion in MS excel returns the Sign of a number

NOTE: This func­tion has dif­fer­ent names, when used as VBA func­tion it is SGN() and when used as Excel for­mula it is SIGN().

For­mat:

As VBA Func­tion : SGN(number)

As Excel For­mula : SIGN(number)

Argu­ments:

  • Num­ber
    • Manda­tory
    • Type: Num­ber
    • Num­ber to get the sign for

Cases:

  1. Num­ber greater than 0 , SGN/SIGN will return 1
  2. Num­ber = 0 , SGN/SIGN will return 0
  3. Num­ber less than 0 , SGN/SIGN will return –1

VBA Exam­ple:

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()

For­mula Example :

SIGN - Formula

SIGN — Formula

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: