Excel Pro Logo

Rounding up in VBA

Quite often we need to round a number up to the nearest n in VBA. The default Round worksheet formula performs a bankers round i.e. to the nearest even number so you can't be sure it will round up.

Usually I head for Google to find the latest funky way of doing it but as you can see there a a myriad of complicated and confusing answers, so I decided to write my own very simple method:

Function RoundUpToN(numToRound As Double, nearestValue As Long) As Long


RoundUpToN = Application.Ceiling(num, nearestValue)


End Function

Hope this helps.

Comments on this article
Add a comment