VBA ABS Function

HomeVBA Functions LIST (Category Wise)VBA ABS Function

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 that 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 VBA ABS function, you need to go through the below example where we have written a VBA code by using it:

Sub example_ABS()
Range("B1").Value = Abs(Range("A1"))
End Sub

In the above example, we have used the value from the 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 the cell B1.

So basically when you run this code it simply takes the value from the 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.

Related Function

ABS | ATN | COS | EXP | FIX | INT | LOG | RND | ROUND | SGN | SQR | TAN