VBA Function: Round

The VBA Round function rounds a number based on the specified number of decimals.


Round(number, decimals)

Example of Usage

Using the Round function to round a number to 2 decimals:

Sub example()

    number = 12.3456
    rounded = Round(number, 2)
    MsgBox rounded 'Returns 12.35
End Sub

Using the Round function to round different numerical values:

Sub example()

    MsgBox Round(14.2) 'Returns: 14
    MsgBox Round(-14.2) 'Returns: -14
    MsgBox Round("14.2") 'Returns: 14
    MsgBox Round("-14.2") 'Returns: -14
    MsgBox Round(9.5) 'Returns: 10
    MsgBox Round(-9.5) 'Returns: -10
    MsgBox Round(1.25, 1) 'Returns: 1.2
    MsgBox Round(50, 1) 'Returns: 50
    MsgBox Round(4532.6351, 2) 'Returns: 4532.64
End Sub