TOP

VBA Function: Abs

YouLibreCalc for Excel logo

Description

The VBA Abs function returns the absolute value of a number.


Syntax Abs

Abs(number)

VBA Abs Example

Applying the Abs function to the result of a subtraction to get a positive result:

Sub AbsExample()

      number1=124.54
      number2=189.36
    
      difference = Abs(number1 - number2) 'Abs(-64.82)

      MsgBox difference 'Returns: 64.82
    
      difference = Abs(number2 - number1) 'Abs(64.82)

      MsgBox difference 'Also returns: 64.82
    
end sub