+ Reply to Thread
Results 1 to 7 of 7

Finding the closet two numbers

  1. #1
    Registered User
    Join Date
    11-27-2007
    Posts
    2

    Finding the closet two numbers

    Hi, i have a list of numbers in excel, i want to find the two that are the closet to each other.

    For example if the list was 2, 4, 9, 152, 153, 234, 324, 521

    the closet numbers would be 152 and 153 and the difference between them would be 1 (smallest difference of any combinantion of two of the numbers).


    Is there a function to do this? if not is there any other way to do this?

    Hope this is clear.

    Thanks you in advance.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Assuming the numbers are listed in ascending order and are in range A2:A9, then try:

    For 1st Number:
    Please Login or Register  to view this content.
    and

    for next number
    Please Login or Register  to view this content.
    both formulas must be confirmed with CTRL+SHIFT+ENTER not just ENTER. You will see { } brackets appear.

    After any adjustments to the formula you must reconfirm with CSE keys

    See attachment for sample.
    Attached Files Attached Files
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    If the numbers are in column A in sequential number, then you could use

    =MAX(A2)-MIN(A1) copy down the column
    oldchippy
    -------------


    Blessed are those who can give without remembering and take without forgetting

    If you are happy with the help you have received, please click the <--- STAR icon on the left - Thanks.

    Click here >>> Top Excel links for beginners to Experts

    Forum Rules >>>Please don't forget to read these

  4. #4
    Registered User
    Join Date
    11-27-2007
    Posts
    2
    The numbers are not in sequential order and cannot be put into, any other ideas?

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Perhaps you can use a helper column that relists your numbers in sequential order, then you can apply my previous formulas to the new range.

    Use formula: =Small($A$2:$A$1000,Row(A1)) copied down to get the reordered list... adjust range to suit.

  6. #6
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Or this in column B

    =A1-SMALL(A:A,1) copied down

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Finding the closet two numbers

    I'm not sure if you're looking for the 2 closest values or the smallest difference between the 2 closest values.

    If your data is in A1:A10

    NOTE: Array formulas are committed with CTRL+SHIFT+ENTER, instead of just ENTER.
    Please Login or Register  to view this content.
    Using your posted data:
    C1 returns 1
    C2 returns 152
    C3 returns 153

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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