+ Reply to Thread
Results 1 to 4 of 4

Thread: The Closest numbers to a number from a list ???

  1. #1
    Registered User
    Join Date
    04-27-2005
    Posts
    12

    The Closest numbers to a number from a list ???

    Hi experts. I have a data list (A1:A18) as it shows below:

    10
    15
    20
    25
    30
    35
    40
    45
    50
    55
    60
    65
    70
    75
    80
    85
    90
    95

    in cell C1 we will set any number among 10 and 95, let's say, 41.

    How can I find the two closest numbers to number (set in cell C1) from the list (list in ascendent order from top to bottom)?.

    For this case, the closest to 41:

    In Cell D1 (number before): 40
    In Cell E1 (number after): 45

    If I enter 95 the results that I expect will be:

    Low Match: 90
    High Match: 95

    in the inverse case:

    If I enter 10 the results that I expect will be:

    Low Match: 10
    High Match: 15

    If my number is 45, are the two closest numbers 40 and 45 the results that I expect will be:

    Low Match: 40
    High Match: 45

    And number in cell C1 not always would be integer, per example If the number is 26.3 the results that I expect will be:

    Low Match: 25
    High Match: 30

    Thanks in advance.
    "Strong is who knows his own capacities, but is still stronger who also knows his own weaknesses". Deladier M.

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: The Closest numbers to a number from a list ???

    One way:

    D1: =SMALL(INDEX(IF(ABS($A$1:$A$18-$C$1)=SMALL(ABS($A$1:$A$18-$C1),{1,2}),$A$1:$A$18),0),COLUMNS($D1:D1))
    confirmed with CTRL + SHIFT + ENTER
    copied to E1

    this will return the two closest matching values in ascending order (irrespective of which is closer to target).

  3. #3
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,784

    Re: The Closest numbers to a number from a list ???

    another is to add a helper with inverted range
    see attached
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    04-27-2005
    Posts
    12

    Re: The Closest numbers to a number from a list ???

    Thank you DonkeyOte and martindwilson, both options work perfect!
    Last edited by Deladier; 03-23-2010 at 04:36 PM.
    "Strong is who knows his own capacities, but is still stronger who also knows his own weaknesses". Deladier M.

+ 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.2.0