VBA ROUND Function (Syntax + Example)

- Written by Puneet

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

example-vba-round-function
Sub example_ROUND()
Range("B1").Value = Round(Range("A1"), 2)
End Sub

In the above code, we have used ROUND to round the number in cell A1. As a result, it has rounded that 15-decimal number to two decimals.