Dec 17th, 2010, 02:00 PM
Excel VBA - Easy Roundup Proc for Integer Numerator and Decimal Denominator
The following is a nice, eloquent way to selectively round up decimal numbers to the next highest integer --- sort of a ceiling procedure.
You could theoretically modify this to do division with two decimal numbers as well. The logic would nearly be the same. I've seen other Roundup methods, some using Case...Select Structures and others using called functions. This could just be dropped into your Sub without calling a procedure, especially if you're looking for a quick and dirty approach.
Dim intNum as Integer
Dim sglDenom as Single
Dim intQuotient as Integer
Dim intResult as Integer
intQuotient = Int(intNum/sglDenom)
If intNum Mod intQuotient = 0 Then
intResult = intQuotient
intResult = intQuotient + 1
Last edited by Hack; Dec 17th, 2010 at 02:33 PM.
Reason: Modified Thread Title To Include Office Product Name
Dec 17th, 2010, 02:32 PM
Re: Easy Roundup Proc for Integer Numerator and Decimal Denominator
Moved To The CodeBank
Will this work with any verison of Excel?
Dec 17th, 2010, 02:45 PM
Re: Excel VBA - Easy Roundup Proc for Integer Numerator and Decimal Denominator
This procedure was run using Access VBA 2002/2003. I just tested it with Excel 2003, and it worked. Added benefit with Excel would be that the Mod function is a Worksheet function, as opposed to a backend function --- however, I tested it with the VBA built-in Mod function, not the Excel Worksheet function.
Click Here to Expand Forum to Full Width
Survey posted by VBForums.