I believe you will need to make this function yourself, as follows (I'm not aware of a function in VBA which works as Excel's native Round function, which allows you to round to the nearest 1000 etc):
Sub add_round()
Dim rng As Range
For Each rng In Selection
rng.Value = Round(rng.Value / 10000, 0) * 10000
Next rng
End Sub
Alternatively you can tell VBA to use the native Excel function like this:
Sub add_round()
Dim rng As Range
For Each rng In Selection
rng.Value = Application.WorksheetFunction.Round(rng.Value, - 4)
Next rng
End Sub
Answer from Grade 'Eh' Bacon on Stack OverflowRoundUp to nearest 1000 using VBA
Excel VBA Rounding - Stack Overflow
Excel Rounding VBA - Stack Overflow
VBA Rounding a variable to the nearest ten thousand
Videos
Hello r/excel! I am trying to round a variable (y) to the nearest ten thousand. For example, I will set y = to the max of a range. Let's say the max comes to 255,084 dollars. I'd like to round this number to 260,000. Is this possible? Below is my VBA thus far...
Sub SGA_Consolidate()
Application.ScreenUpdating = False
Dim y As Long
y = WorksheetFunction.Max(Range("C26:N27"))
Sheets("SG&A").ChartObjects("Chart 4").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScale = y + 50000
Sheets("SG&A").Range("A1").Select
Application.ScreenUpdating = True
End SubIt's simple math. Given a number X and a rounding factor N, the formula would be:
round(X / N)*N
Integrated Answer
X = 1234 'number to round
N = 5 'rounding factor
round(X/N)*N 'result is 1235
For floating point to integer, 1234.564 to 1235, (this is VB specific, most other languages simply truncate) do:
int(1234.564) 'result is 1235
Beware: VB uses Bankers Rounding, to the nearest even number, which can be surprising if you're not aware of it:
msgbox round(1.5) 'result to 2
msgbox round(2.5) 'yes, result to 2 too
Thank you everyone.