TOP

VBA Function: Round

Description

The VBA Round function rounds a number to the specified number of decimal places.


Round Syntax

Round(number, number_decimal_places)

VBA Round Example

Using the Round function to round a number to 2 decimal places:

Sub RoundExample1()

      number = 12.3456
    
      round = Round(number, 2)
    
      MsgBox round 'Returns 12.35
    
end sub

Using the Round function to round various numeric values:

Sub RoundExample2()

      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