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.
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).
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
another is to add a helper with inverted range
see attached
"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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks