Returns the absolute value of a number (Variant).

numberThe number you want the absolute of (Variant).

* The absolute value of a number is the number without its sign.
* The data type of the value returned is the same as the data type of the number passed in.
* The "number" can be any valid numeric expression.
* If "number" is Null, then Null is returned.
* If "number" is an uninitialised variable, then 0 is returned.
* The equivalent Excel function is Application.WorksheetFunction.ABS
* The equivalent .NET function is System.Math.Abs
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print Abs(1)               '= 1  
Debug.Print Abs(-1) '= 1
Debug.Print Abs(2.4) '= 2.4
Debug.Print Abs(-2.4) '= 2.4
Debug.Print Abs(True) '= 1
Debug.Print Abs(False) '= 0
Debug.Print Abs(Null) '= Null

'Abs(#of an Integer#) '= "Integer"
Dim vResult As Variant
vResult = Abs(10)
Debug.Print TypeName(vResult) '= "Integer"

'Abs(#of a Boolean#) '= "Integer"
vResult = Abs(True)
Debug.Print TypeName(vResult) '= "Integer"

'Abs(#of a Single#) '= "Single"
'Abs(#of a Double#) '= "Double"

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top