Excel VBA - Easy Roundup Proc for Integer Numerator and Decimal Denominator-VBForums
Results 1 to 3 of 3

Thread: Excel VBA - Easy Roundup Proc for Integer Numerator and Decimal Denominator

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    2

    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.

    Code:
    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
    Else
         intResult = intQuotient + 1
    End If
    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.
    Last edited by Hack; Dec 17th, 2010 at 01:33 PM. Reason: Modified Thread Title To Include Office Product Name

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Easy Roundup Proc for Integer Numerator and Decimal Denominator

    Moved To The CodeBank

    Will this work with any verison of Excel?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    2

    Re: Excel VBA - Easy Roundup Proc for Integer Numerator and Decimal Denominator

    Hack,

    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.

    Jeremy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.