How to Round Down Values in VBA (With Examples)


You can use the RoundDown method in VBA to round values down.

This function uses the following basic syntax:

Sub RoundDownValue()
    Range("B1") = WorksheetFunction.RoundDown(Range("A1"), 0)
End Sub

This particular example will round down the value in cell A1 to the nearest whole number and display the result in cell B1.

Note that the second argument in the RoundDown method specifies the number of digits to round where:

  • -3 rounds down to the nearest thousand
  • -2 rounds down to the nearest hundred
  • -1 rounds down to the nearest ten
  • 0 rounds down to the nearest whole number
  • 1 rounds down to the nearest tenth (one decimal place)
  • 2 rounds down to the nearest hundredth (two decimal places)
  • 3 rounds down to the nearest thousandth (three decimal places)

And so on.

The following examples show how to use the RoundDown method in practice.

Related: How to Round Up Values in VBA

Example 1: Round Down to Nearest Whole Number in VBA

We can create the following macro to round down the value in cell A1 to the nearest whole number and display the result in cell B1:

Sub RoundDownValue()
    Range("B1") = WorksheetFunction.RoundDown(Range("A1"), 0)
End Sub

When we run this macro, we receive the following output:

Notice that the value 1,432.78 in cell A1 has been rounded down to the nearest whole number of 1,432 in cell B1.

Example 2: Round Down to Nearest Hundred in VBA

We can create the following macro to round down the value in cell A1 to the nearest hundred and display the result in cell B1:

Sub RoundDownValue()
    Range("B1") = WorksheetFunction.RoundDown(Range("A1"), -2)
End Sub

When we run this macro, we receive the following output:

Notice that the value 1,432.78 in cell A1 has been rounded down to the nearest hundred of 1,400 in cell B1.

Example 3: Round Down to Nearest Tenth in VBA

We can create the following macro to round down the value in cell A1 to the nearest tenth (i.e. one decimal place) and display the result in cell B1:

Sub RoundDownValue()
    Range("B1") = WorksheetFunction.RoundDown(Range("A1"), 1)
End Sub

When we run this macro, we receive the following output:

Notice that the value 1,432.78 in cell A1 has been rounded down to the nearest tenth of 1,432.7 in cell B1.

Note: You can find the complete documentation for the VBA RoundDown method here.

Additional Resources

The following tutorials explain how to perform other common tasks in VBA:

VBA: How to Write SUMIF and SUMIFS Functions
VBA: How to Write COUNTIF and COUNTIFS Functions
VBA: How to Write AVERAGEIF and AVERAGEIFS Functions

One Reply to “How to Round Down Values in VBA (With Examples)”

  1. Function For RoundDown is:

    Public Function ROUNDDOWN(Num As Variant) As Double
    If Nz(Num, “”) “” Then
    ROUNDDOWN = Fix(Nz(Num, 0))
    End If
    End Function

Leave a Reply

Your email address will not be published. Required fields are marked *