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

Last Updated on January 11, 2023 by token

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 eual to 0. In the case of negative number, the function returns -1. For positive numbers, the value is 1. In the case of zero, the function returns 0.

VBA Sgn function – Syntax

Sgn (Number)

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

Function return : Number / sign of number

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

VB Sgn function – Additional information

  • None

Sgn VisualBasic function – Where to use?

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

This article is a part of the VBA Excel function list. You can find a list of all VBA functions here: VBA functions .

Leave a comment

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

%d bloggers like this: