How to use the VBA ROUND Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA ROUND Function (Syntax + Example)

The VBA ROUND function is listed under the math category of VBA functions. When you use it in a VBA code, it rounds a number to specific decimals places. In simple words, with ROUND you can round a number and you can specify the decimals places you want to round that number to.

Syntax

Round(Number, [NumDigitsAfterDecimal])

Arguments

  • Number: The number you want to round.
  • [NumDigitsAfterDecimal]: The number of decimal places that you want to round to [This is an optional argument and if omitted VBA takes 0 by default].

Example

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

Sub example_ROUND()
Range("B1").Value = Round(Range("A1"), 2)
End Sub

In the above code, we have used ROUND to round the number that we have in the cell A1 and in the result, it has round that 15 decimals number to two decimals number.

Related Functions

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