+ Reply to Thread
Results 1 to 11 of 11

Rounding up between incremental numbers

  1. #1
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    136

    Rounding up between incremental numbers

    Hi All,

    I have a set of numbers that increase in increments varying by 5 at the start with the interval becoming larger in steps as the numbers get higher. Users are able to input a figure into a cell and a worksheet change event should round the figure up based on the set increments in the list. The first 20 increments look like this - 5, 10, 15, 20, 25, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, etc. If the user were to input 12, the worksheet change event would round the number between increments 10 and 15 resulting in a rounded figure of 10.

    13 would result in 15
    75 would result in 100
    324 would result in 300, etc.

    I can use ROUNDUP for regular integer intervals but am struggling to find a simple way to roundup between set figures for the worksheet change event. I have attached a workbook with the full increment set. The macro in its base form is:

    Please Login or Register  to view this content.
    Incremental Rounding.png

    Any assistance would be greatly appreaciated!

    Many thanks,
    David
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,448

    Re: Rounding up between incremental numbers

    No need for VBA!

    In E2:

    =XLOOKUP(C2,A2:A148,A2:A148,"",1)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    136

    Re: Rounding up between incremental numbers

    Hi Ali,

    Thanks for the swift reply, much appreciated!

    This formula is perfect. Due to the sheer size and number of formulas involved, I'm utilising a worksheet change event for this task in the actual project to try to keep formula overheads down. I will adapt this formula accordingly and hope I've taken the right approach!

    Many thanks again!
    David

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,448

    Re: Rounding up between incremental numbers

    Glad to have helped.

    If you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2021
    Posts
    5,930

    Re: Rounding up between incremental numbers

    Try this
    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,594

    Re: Rounding up between incremental numbers

    Quote Originally Posted by L plates View Post
    13 would result in 15
    75 would result in 100
    324 would result in 300, etc.
    Quote Originally Posted by L plates View Post
    This formula is perfect.
    Are you sure?

    Here's my understanding.
    Formula:
    =LET(x,A2:A500,y,ABS(x-C2),XLOOKUP(MIN(y),y,x,"""",0,-1))
    vba
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    136

    Re: Rounding up between incremental numbers

    Hi Ali,

    Thanks again for your input and apologies for missing this - the formula you provided looks for the next largest number in the list and while this technically rounds up, does not meet the requirement to round up using the midway point between increments. I will check responses more closely in future.

    Hi Phoucam,

    Your solution fills the requirement exactly - rounding up if the user input is midway between increments or above. Thanks so much! How could I adjust your code to round down from the midway point?

    Many thanks to you both!
    David
    Dave C

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,448

    Re: Rounding up between incremental numbers

    When I read 'round up', I assume it means 'round up', not 'round' (which would go either way depending on the actual value).

    You mention rounding UP in both the thread title AND the opening post, so I don't think you can really blame me (or anyone else) for taking you literally.

    I'll leave it to the others - got to go outside and do some pressure washing of our drive!
    Last edited by AliGW; 11-23-2023 at 06:53 AM.

  9. #9
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2021
    Posts
    5,930

    Re: Rounding up between incremental numbers

    Quote Originally Posted by L plates View Post

    How could I adjust your code to round down from the midway point?
    Change to:

    Range("E2").Value = IIf(v - fi <= en - v, fi, en)

  10. #10
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    136

    Re: Rounding up between incremental numbers

    Thanks Phuocam, that worked. Fisrt I have seen IIf before - extremely useful to have!

    This also seems to do the trick:

    Range("E2").Value = IIf(v - fi > en - v, en, fi)

    Many thanks,
    David

  11. #11
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    136

    Re: Rounding up between incremental numbers

    Quote Originally Posted by AliGW View Post
    When I read 'round up', I assume it means 'round up', not 'round' (which would go either way depending on the actual value).

    You mention rounding UP in both the thread title AND the opening post, so I don't think you can really blame me (or anyone else) for taking you literally.

    I'll leave it to the others - got to go outside and do some pressure washing of our drive!
    No probs Ali - thanks for correcting my terminology - always happy to learn.

+ 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. [SOLVED] Help with an IF formula to return incremental line numbers..
    By TomP1988 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-03-2019, 03:17 AM
  2. Two columns with incremental numbers and repaeting pattern
    By arty123 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 12-30-2016, 06:48 AM
  3. [SOLVED] Incremental House Numbers
    By kumarin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-07-2015, 05:55 AM
  4. Help with Macro code- Incremental Numbers
    By dmighty in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2013, 07:11 AM
  5. [SOLVED] Assign incremental numbers to matching Invoice numbers
    By berger01 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-06-2013, 10:54 AM
  6. Re-generating incremental numbers
    By razaas in forum Excel General
    Replies: 4
    Last Post: 09-05-2011, 04:13 AM
  7. Fill range with incremental numbers
    By Jaymond Flurrie in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-26-2008, 01:13 AM

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