+ Reply to Thread
Results 1 to 22 of 22

Find Highest or Closest number from list

  1. #1
    Registered User
    Join Date
    08-10-2013
    Location
    Stafford, UK
    MS-Off Ver
    Excel 2003
    Posts
    10

    Question Find Highest or Closest number from list

    Hi Guys,

    Since I'm new here, i thought i'd start with something good.

    In column A i have a list of numbers. This list can vary from 1 number, to over 1000 numbers. All of which could be the same, or all of which could be different.

    In Cell B1, i have 1 number.

    Now in cell C1, I need to return a number from the list in column A, that is the closest number higher than the number in B1, or (if there are no numbers higher) return the closest number lower.

    Is there any way of doing this?

    Any help is appreciated.

    Thanks in advance.

  2. #2
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    Well a sample workbook would help greatly, you could try something like this though :
    C1:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    HOWEVER, this will only work if the numbers in column A are sorted;
    With a sample work book, I could probably come up with a sumproduct formula to work with unsorted column A....or anyone else here could
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  3. #3
    Forum Contributor rajeshturaha's Avatar
    Join Date
    08-22-2012
    Location
    Assam, India
    MS-Off Ver
    Excel 2003, 2007
    Posts
    236

    Re: Find Highest or Closest number from list

    Try This

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For any explanation go to

    http://www.excelforum.com/excel-gene...est-value.html
    Rgd
    RT
    If my answer(s) helped you, please add me reputation by click on *

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Find Highest or Closest number from list

    Also perhaps =IF(MIN(IF(A1:A20>H1,A1:A20))=0,MAX(IF(A1:A20<=H1,A1:A20))) were H1 contains your value.

    Commit with Ctrl+Shift+Enter

  5. #5
    Forum Contributor rajeshturaha's Avatar
    Join Date
    08-22-2012
    Location
    Assam, India
    MS-Off Ver
    Excel 2003, 2007
    Posts
    236

    Re: Find Highest or Closest number from list

    I tried your formula it is returning a false error

  6. #6
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    See..3 different respondents, 3 different answers!
    This is what I love about this site !
    IF I got three the same answers, I would be thinking "that must be the best way.."
    BUT, with 3 different ones, you get to test and choose!!!

  7. #7
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    Who's?
    If it's mine, then your data is NOT sorted, and you will probably wind up with errors...thats why I said the data MUST be sorted... sorry

  8. #8
    Forum Contributor
    Join Date
    05-24-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Find Highest or Closest number from list

    this has to be in C1

    =IF(ISERROR(LARGE(A1:A493,SUMPRODUCT(--(A1:A493>=B1+1)*(A1:A493<>"")))),SMALL(A1:A493,SUMPRODUCT(--(A1:A493<=B1-1)*(A1:A493<>""))),LARGE(A1:A493,SUMPRODUCT(--(A1:A493>=B1+1)*(A1:A493<>""))))

    frankly speaking i have taken some references for this this works

    Edit:

    i have considered data in A1 to A493, B1 as value to be match, C1 is result cell
    Last edited by amy_d2; 08-10-2013 at 03:43 AM.
    Click on * below if you find this helpful

    Thanks,
    A

  9. #9
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    The IFERROR functoin will fail if the OP is using 2003 as profile suggests.. just a friendly reminder

  10. #10
    Forum Contributor
    Join Date
    05-24-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Find Highest or Closest number from list

    Ohhhh.. my mistake ,

    this will be good i think thanks dredwolf


    =IF(ERROR.TYPE(LARGE(A1:A493,SUMPRODUCT(--(A1:A493>=B1+1)*(A1:A493<>""))))=6,SMALL(A1:A493,SUMPRODUCT(--(A1:A493<=B1-1)*(A1:A493<>""))),LARGE(A1:A493,SUMPRODUCT(--(A1:A493>=B1+1)*(A1:A493<>""))))

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find Highest or Closest number from list

    @rajeshturaha

    Note that the OP stated: "the closest number higher than the number in B1, or (if there are no numbers higher) return the closest number lower."

    This would seem to contradict the basis of your formula, which will always return the absolute closest.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  12. #12
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    @ amy_d2, Not a problem
    (although...I still think your are using functions not available to 2003 users, at least not without using the built-in macros, which have to be coded in in the named 'Formulas', and macros allowed, ... Error.Type is not one of the "off the shelf" macros I remember... )
    Last edited by dredwolf; 08-10-2013 at 04:24 AM.

  13. #13
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find Highest or Closest number from list

    @Pepe Le Mokko

    "Also perhaps =IF(MIN(IF(A1:A20>H1,A1:A20))=0,MAX(IF(A1:A20<=H1,A1:A20))) were H1 contains your value"

    This is good, but you simply left off your the FALSE part of your statement!

    Correct to e.g.:

    =IFERROR(1/(1/MIN(IF(A1:A20>H1,A1:A20))),MAX(IF(A1:A20<=H1,A1:A20)))

    Again, array-entered.

    Regards

  14. #14
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    @ XOR LX,
    Again, the IFERROR function is contra indicated, profile suggests only 2003 version, if your going to use an iferror, then supply the VBA to support it , please !

  15. #15
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find Highest or Closest number from list

    @dredwolf

    Apologies. Really shouldn't have forgotten that, especially since you only mentioned it a couple of posts back!

    Time for another coffee!

  16. #16
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find Highest or Closest number from list

    In that case, Pepe's formula will just have to be extended the long way round:

    =IF(MIN(IF(A1:A20>H1,A1:A20))=0,MAX(IF(A1:A20<=H1,A1:A20)),MIN(IF(A1:A20>H1,A1:A20)))

    Regards

  17. #17
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    LOL
    is not a problem for me, we just have to keep our public informed, if we are goig to use something they don't have, we better be able to supply it too them

  18. #18
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find Highest or Closest number from list

    Of course, if Microsoft had got round to introducing that rather obvious formula 15 years ago...

  19. #19
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Find Highest or Closest number from list

    True...
    But then us people trying to be 'Guru''s would have nothing to do...

  20. #20
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find Highest or Closest number from list

    This should work for any version of Excel.
    The numbers can be in any order.

    Where A2:A32 is the range, and C2 the target.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    [EDIT]
    Oops! This returns the nearest or equal, that's not what the problem is ...
    Attached Files Attached Files
    Last edited by Marcol; 08-10-2013 at 06:58 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  21. #21
    Registered User
    Join Date
    08-10-2013
    Location
    Stafford, UK
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Find Highest or Closest number from list

    Hey Guys,

    Thanks for all the help on this!

    amy_d2 's solution has worked best for me as sorting the numbers would not be a viable solution.

    I have numerous VBA routines already in place to handle any errors raised.

    Thanks again!

  22. #22
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find Highest or Closest number from list

    Quote Originally Posted by XOR LX View Post
    @Pepe Le Mokko
    Correct to e.g.:

    =IFERROR(1/(1/MIN(IF(A1:A20>H1,A1:A20))),MAX(IF(A1:A20<=H1,A1:A20)))

    Again, array-entered.

    Regards
    Might be a small point but if the target value equals the max value then your formula returns the max value.
    "if there are no numbers higher" return the closest number lower
    Maybe this CSE array?
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    There might be more problems if negative numbers are involved.

+ 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. VBA code to find highest and 2nd highest number based in criteria
    By Michael007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2011, 08:38 AM
  2. Find the closest number
    By xyba in forum Excel General
    Replies: 9
    Last Post: 10-21-2010, 04:20 AM
  3. find closest date (number) in a range
    By wamp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2010, 01:50 PM
  4. The Closest numbers to a number from a list ???
    By Deladier in forum Excel General
    Replies: 3
    Last Post: 03-11-2010, 12:44 PM
  5. Find Number Closest to Zero
    By snapa in forum Excel General
    Replies: 2
    Last Post: 12-04-2009, 05:34 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