+ Reply to Thread
Results 1 to 5 of 5

Rounding up to the next whole number in macro.

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Nottinghamshire
    MS-Off Ver
    2007
    Posts
    5

    Rounding up to the next whole number in macro.

    Hi guys.

    I have the following code.
    Please Login or Register  to view this content.
    I appreciate its a little untidy for which i apologise.

    The problem i have is that
    Please Login or Register  to view this content.
    produces a number that in most cases will have at least one decimal place and i need to round this to a whole number but always up and never down, (5.001 should become 6). Can anyone offer any suggestions on how to achieve this?

    The idea of this code is to calculate the cost of towing a glider to a particular height. there is a fixed price to tow to 2000ft (in this case its £18) so any height upto 2000 is £18. above this its another £3.50 for every 500ft or part there of, and this is where the rounding up comes in. My code takes the 2000 off the tow height to leave any extra chargeable height, and then divides that by 500 to give how many "500fts" there are left (ie. 1500ft is 3x500ft). as long as the number is exactly dividable by 500 there is no problem but if its say, 1600ft, the result is 3.2, but because its charged for every 500ft, or part of, i need the result to be 4 so the calculation works correctly.

    The values are not hard written into the code as prices and heights could change in the future hence the reference to a worksheet.

    Sorry if im babbling on, and i hope you can understand what im trying to achieve.

    thanks in advance

    Tim

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Rounding up to the next whole number in macro.

    Try

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    07-01-2015
    Location
    Nottinghamshire
    MS-Off Ver
    2007
    Posts
    5

    Re: Rounding up to the next whole number in macro.

    Hi. thanks for your help.

    i moved a bracket or two around and came up with this...

    Please Login or Register  to view this content.
    however it returns daft figures.

    If Cell B8 = 18
    cell B9 = 2000
    cell B10 = 2.5
    cell B11 = 500

    i put 2000 into AerotowHeight and the code returns "5008" which should be 18.
    i put 3200 into aerotowheight and the code returns "8008" which should be 25.5

    any ideas?

  4. #4
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Rounding up to the next whole number in macro.

    Your formula is incorrect:

    With your values :

    X = 18 + Roundup(2000 - 2000/500)*2.5
    X = 18 + Roundup(2000 - 4)*2.5
    X = 18 + 1996*2.5
    X = 5008

    Your formula should be :
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-01-2015
    Location
    Nottinghamshire
    MS-Off Ver
    2007
    Posts
    5

    Re: Rounding up to the next whole number in macro.

    hi. i tryed that and it worked except that id didnt work for heights of less than 2000, it gave a price of less than 18. However, iv used this and it seems to work fine...

    Please Login or Register  to view this content.
    thanks for all your help!!!

    Tim

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HELP Need macro to convert text to number without rounding.
    By abordeau in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2014, 02:41 PM
  2. [SOLVED] Cell with text and number, not rounding to closest full number
    By cblp in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-03-2014, 07:51 PM
  3. [SOLVED] Rounding the number produced by an evaluated expression to the nearest number in CF
    By orly_sm in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-29-2013, 09:16 AM
  4. [SOLVED] Rounding up a decimel number to a whole number
    By Gunner 14 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-27-2012, 03:21 AM
  5. Rounding whole number down
    By johncouzins in forum Excel General
    Replies: 3
    Last Post: 01-18-2011, 07:33 AM
  6. Number Rounding
    By scsuflyboy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-09-2008, 03:24 PM
  7. Rounding to the next whole number
    By mpeplow in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-19-2007, 04:46 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1