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

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

 

You may also like...

Leave a Reply

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

%d bloggers like this: