Round to the nearest thousand
To round a number to the nearest thousand we need to apply the Excel ROUND function
Example: Round to the nearest thousand
=ROUND(B5,C5)
|
The formula uses the Excel ROUND function to round the selected number in cell B5 to the nearest thousand by using the -3 as the num_digit.
|
Dim ws As Worksheet
ws.Range("D5") = Application.WorksheetFunction.Round(ws.Range("B5"), ws.Range("C5"))
End Sub
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheet Name: Have a worksheet named Analysis.
Value to Round: If using the exact VBA code ensure that the value that you want to round to the nearest thousand is captured in cell ("B5").
Number of Digits: The value (-3) in cell ("C5") represents the number of digits that the selected number should be rounded. -3 represents a rounding to the nearest thousand.
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Value to Round: Select the value that you want to round to the nearest thousand by changing the cell reference ("B5") in the VBA code to any cell in the worksheet that contains the value that you want to round to the nearest thousand and doesn't conflict with the formula.
Number of Digits: You can select the cell that contains the number of digits, which in this example will be -3, by changing the cell reference ("C5") to any cell in the worksheet that contains a value of -3 and doesn't conflict with the formula. You can also hardcode the number of digits directly into the VBA code by replacing ws.Range("C5") with -3.