The VBA Round function rounds a numbers to a specified number of decimal places.
The syntax of the function is:
Where the function arguments are:
Number | - | The number that you want to round. |
[NumDigitsAfterDecimal] | - |
An optional positive integer specifying the number of decimal places that you want to round to. If the [NumDigitsAfterDecimal] argument is omitted, it takes on the default value 0 (i.e. round to the nearest integer). |
' Round the number 77.777 to 2 and 0 decimal places.
Dim res1 As Double
Dim res2 As Double
res1 = Round( 77.777, 2 )
' Now, res1 = 77.78 and res2 = 78
res2 = Round( 77.777 ) |
In the above VBA code:
If the [NumDigitsAfterDecimal] argument that is supplied to the Round function is negative, you will get the error:
If one or both of the arguments to the Round function cannot be interpreted as numeric values, the function will return the error: