+ Reply to Thread
Results 1 to 9 of 9

Custom Rounding And IF Statement In One Formula....

  1. #1
    Registered User
    Join Date
    03-16-2013
    Location
    Portland, OR
    MS-Off Ver
    Excel 2010
    Posts
    11

    Question Custom Rounding And IF Statement In One Formula....

    Thanks to shg I got the first half of my challenge resolved in Round to Nearest Half Based On Defined Range of Decimal thread.

    So here is what happens in the first half of the equation....I round numbers to the nearest half based on a specific range of decimals in the original number. For example if the number in A1 is:

    28.0 to 28.399 then rounds DOWN to 28
    28.4 to 28.799 then rounds to 28.5
    28.8 to 28.99 then rounds UP to 29

    for this I am using shg's equation:
    Please Login or Register  to view this content.
    This is all I needed for most of my numbers.....but one part goes one step further.....

    NOW THE SECOND HALF......Once the first half of the equation rounds the number above, I need the second half of the equation to then do the following. If the resulting number from the first part of equation above is:

    • 1 through 3 = its own size (1 is 1, 1.5 is 1.5, 2 is 2, 2.5 is 2.5, 3 is 3)
    • 3.5 to 7 = 3
    • 7.5 and above = 4
    • Resulting number from last part of the formula multiply by 2

    So this will end up being only 1, 1.5, 2, 2.5, 3, or 4 multipled by 2.

    I am pretty sure this second part would be an IF statement (or maybe there is a more efficient way), but I am still learning the ins and outs of that....but I don't know how to use the first formula and add the needed second part into all one forumula.

  2. #2
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Re: Custom Rounding And IF Statement In One Formula....

    There is probably a tidier appoach to this but try:

    =IF(A<=3,(A)*2,IF(A<=7,6,8))

    Replace A with the formula from shg.If i;ve understood correctly you will only need to multiply by 2 when shg's bit results in the 1 to 3 range. The next two situations will always be 6 and 8.
    Say thanks, click *

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Custom Rounding And IF Statement In One Formula....

    =choose(match(int(a1) + lookup(round(mod(a1,1), 6), {0,4,8}/10, {0,5,10}/10), {0,3.5,7.5}), 2*int(a1) + lookup(round(mod(a1,1), 6), {0,4,8}/10, {0,5,10}/10), 6, 8)
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    03-16-2013
    Location
    Portland, OR
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Custom Rounding And IF Statement In One Formula....

    Quote Originally Posted by Harribone View Post
    There is probably a tidier appoach to this but try:

    =IF(A<=3,(A)*2,IF(A<=7,6,8))

    Replace A with the formula from shg.If i;ve understood correctly you will only need to multiply by 2 when shg's bit results in the 1 to 3 range. The next two situations will always be 6 and 8.

    Thank you! I think you are REALLY close. but.... the result from shg's rounding formula could result with any number from 1 and above at .5 increments. So the number might be 1.5 or 37.

    So we need to get the number from shg's formula and then have it run the following IF statement
    • 1 through 3 = its own size (1 is 1, 1.5 is 1.5, 2 is 2, 2.5 is 2.5, 3 is 3)
    • 3.5 to 7 = 3
    • 7.5 and above = 4

    This will result in either 1, 1.5, 2, 2.5, 3, or 4. We would THEN multiply that number by 2.

    I think the first part of your IF statement is correct, but the last part is a little off with the 3.5 to 7 = 3 and the 7.5 and above = 4 parts....

  5. #5
    Registered User
    Join Date
    03-16-2013
    Location
    Portland, OR
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Custom Rounding And IF Statement In One Formula....

    Quote Originally Posted by shg View Post
    =choose(match(int(a1) + lookup(round(mod(a1,1), 6), {0,4,8}/10, {0,5,10}/10), {0,3.5,7.5}), 2*int(a1) + lookup(round(mod(a1,1), 6), {0,4,8}/10, {0,5,10}/10), 6, 8)
    SOOOOO Close. These two ranges work PERFECTLY!
    • 3.5 to 7 = 3
    • 7.5 and above = 4


    But the first one "1 through 3 = its own size (1 is 1, 1.5 is 1.5, 2 is 2, 2.5 is 2.5, 3 is 3)" adds an extra .5 to the number if it is whole number and gives the wrong number when if the original number ends in .5 . And I cannot see why...
    Last edited by HobbesIsReal; 08-03-2013 at 05:17 PM.

  6. #6
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Re: Custom Rounding And IF Statement In One Formula....

    My approach does what you require:

    If less than or equal to 3 then use shg formula and multiply by 2, else:
    if less than or equal to 7 return 3 and multiply by 2 (which will always be 6)
    if neither of these is correct the number must be gretaer than 7 therefore return 4 multiplied by 2 (which is always 8)

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Custom Rounding And IF Statement In One Formula....

    Missing a pair of parens:

    =CHOOSE(MATCH(INT(A1) + LOOKUP(ROUND(MOD(A1,1), 6), {0,4,8}/10, {0,5,10}/10), {0,3.5,7.5}), 2 * (INT(A1) + LOOKUP(ROUND(MOD(A1,1), 6), {0,4,8}/10, {0,5,10}/10)), 6, 8)

  8. #8
    Registered User
    Join Date
    03-16-2013
    Location
    Portland, OR
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Custom Rounding And IF Statement In One Formula....

    Quote Originally Posted by shg View Post
    Missing a pair of parens:

    =CHOOSE(MATCH(INT(A1) + LOOKUP(ROUND(MOD(A1,1), 6), {0,4,8}/10, {0,5,10}/10), {0,3.5,7.5}), 2 * (INT(A1) + LOOKUP(ROUND(MOD(A1,1), 6), {0,4,8}/10, {0,5,10}/10)), 6, 8)
    THAT WORKED!

    Again, you saved my day as I need this spreadsheet for work by Monday morning and I got everything else working perfectly except this part was a little beyond me.

    THANK You both for your help!
    Last edited by HobbesIsReal; 08-03-2013 at 06:21 PM.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Custom Rounding And IF Statement In One Formula....

    I would do it in two steps rather than put all of that in a single cell.

+ 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] Rounding decimals (...or custom number formatting?)
    By kitpierce in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-13-2013, 06:03 PM
  2. Custom formatting code - rounding problem
    By venkys4u in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2012, 12:25 AM
  3. Excel 2007 : custom rounding to every .05.
    By ameerulislam in forum Excel General
    Replies: 2
    Last Post: 10-01-2011, 05:42 AM
  4. Custom rounding function
    By doctordowling in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2010, 03:42 PM
  5. [SOLVED] Custom format rounding
    By Ray88 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-14-2006, 06:45 AM

Tags for this Thread

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