Sgn VBA function – How to return a sign of a number

1. Sgn VBA function – Description

The Sgn VBA function   returns the sign of the number specified in the argument. The function determines the sign, so it checks whether the argument is a negative, positive, or zero. In the case of a negative number, the function returns -1. For added numbers, the value is 1. In the case of zero, the function returns 0.

2. VBA Sgn function – Syntax

Sgn (Number)

Number : Indicating the number for which we want to return a sign.

Function return : Number / sign of number

3. VBA Sgn function – Example

How to use Sgn function   in VBA Excel? Below are examples of using the Sgn function in the VisualBasic Editor.

Example 1 : Determining the sign of a number using the Sgn function. The result presented in the MsgBox window.

MsgBox Sgn (-9.25) 
MsgBox Sgn (9.25) 
MsgBox Sgn (0)

Example 2 : Sgn VBA function – sign of number. The result presented in the cells of the sheet.

Range ("A1") = Sgn (-9.25)
Range ("A2") = Sgn (9.25)
Range ("A3") = Sgn (0)
Excel VBA functions - Sgn VBA function
Excel VBA functions – Sgn VBA function

4. VB Sgn function – Additional information

  • None

5. Sgn VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

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

%d bloggers like this: