0

I'm just wondering how I can round off decimals to the nearest whole number. So the problem is that I'm using Round(Total / i, 0) code, but when the value is something like .5 decimals, it doesn't round off.

Example: The value is 92.5, but the result only shows 92, not 93.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
cjvdg
  • 497
  • 2
  • 15
  • 2
    Use `WorksheetFunction.Round`. `Round` uses bankers rounding, as noted in the [docs](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function). – BigBen May 28 '21 at 02:34

1 Answers1

0

You can utilize Roundup() function. For VBA try like-

Sub rUP()
Dim x As Double

    x = 92.5
    MsgBox Application.WorksheetFunction.RoundUp(x, 0)
    
End Sub
Harun24hr
  • 30,391
  • 4
  • 21
  • 36
  • 3
    That's not what OP wants though. For example, `92.3` would get rounded to `93`, not `92`. `WorksheetFunction.Round` seems like what OP wants: "to the nearest whole number" – BigBen May 28 '21 at 02:38
  • @BigBen In that case your suggestion is correct. He need to use application Round function like `Application.WorksheetFunction.Round(x, 0)` – Harun24hr May 28 '21 at 02:41
  • .... and strangely enough, it seems that OP asked [a similar question](https://stackoverflow.com/questions/67067347/rounding-of-decimal-number-to-whole-number) last month, which was also closed as a duplicate (by me). – BigBen May 28 '21 at 02:42