VBA ABS Function (Get Absolute Value)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA ABS function is listed under the math category of VBA functions. When you use it in a VBA code, it returns an absolute number in the result. In simple words, it returns a non-negative number which means if you specify a negative number it will remove its sign and returns it in the result.

Syntax

Abs(Number)

Arguments

  • Number: The number which you want to convert into an absolute value (number).

Example

To practically understand how to use the VBA ABS function, you need to go through the below example where we have written a VBA code by using it:

example-vba-abs-function
Sub example_ABS()
Range("B1").Value = Abs(Range("A1"))
End Sub

In the above example, we have used the value from cell A1 where we have a negative number (-1029) and then we have used the ABS function to convert that value into an absolute number and enter that value in cell B1. So basically when you run this code it simply takes the value from cell A1 and converts it into an absolute number.

Notes

  • If the value specified is a value other than a number or a number that can’t be recognized as a number, VBA will return the run-time 13 error.
  • If the value supplied is NULL then it will return a NULL in the result.