Rounding Up

SteveHirsch

New member
Local time
Today, 05:26
Joined
Apr 21, 2005
Messages
5
Have the need to Round up to the next whole. If I have 1.2, I would like it to Round to 2. Is this possible? :
 
You could use a function...something like this:

Public Function RoundUp(varNumber As Variant) As Variant
If varNumber > Int(varNumber) Then
RoundUp = Int(varNumber) + 1
Else
RoundUp = varNumber
End If
End Function
 
You don't need anything complicated.

Int(MyNum) +1

I assume you have positive numbers only, as -1.4 becomes -1, etc.
 
Last edited:
Roundup

Int(MyNum) +1 worked........Not complicated.....just hard to think of at the time......Thanks all
:)
 
If you have a whole number (for example 1.0) JStockton's method will properly not round it up to 2 but mresann's simpler solution will.

Don't know if that matters.
 
Actually, Dwight brought up a point, although he incorrectly said my version was correct, which it is NOT. When I gave the answer earlier, I did not consider whole numbers, which of course should NOT be rounded up given your example (for instance, 1.0 should NOT round up to 2, etc.) Sometimes simplicity is plain wrong, and I am guilty this time around.

Therefore, just use the Iif statement as follows:

Iif(Int(MyNum)=MyNum, MyNum, Int(MyNum) +1)

This will ensure whole numbers like 1.0 stay the same, while 1.1 get rounded up to 2.

Thanks Dwight.
 

Users who are viewing this thread

Back
Top Bottom