Excel: Find closest value
Table of Contents
Find closest values and return adjacent values
Question: How to find closest number in a list?
Answer:
Array formula in cell C2:
How to create an array formula
- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar.
- Press and hold Ctrl + Shift.
- Press Enter once
- Release all keys
Explaining array formula
INDEX(A2:A26,MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0))
Step 1 - Return absolute values of numbers in an array, numbers without its sign
INDEX(A2:A26,MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0))
ABS(number) returns the absolute value of a number, a number without its sign.
ABS(A2:A26-C1)
becomes
ABS({3, 77, 7, 62, 66, 48, 83, 57, 69, 10, 86, 42, 71, 90, 34, 17, 73, 77, 20, 37, 59, 50, 99} - 43)
becomes
ABS{-40, 34, -36, 19, 23, 5, 40, 14, 26, -33, 43, -1, 28, 47, -9, -26, 30, 34, -23, -6, 16, 7, 56})
and returns
{40, 34, 36, 19, 23, 5, 40, 14, 26, 33, 43, 1, 28, 47, 9, 26, 30, 34, 23, 6, 16, 7, 56}
Step 2 - Return the smallest number
INDEX(A2:A26,MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0))
MIN(number1,[number2]) returns the smallest number in a set of values. Ignores logical values and text
MIN(ABS(A2:A26-C1))
MIN({40, 34, 36, 19, 23, 5, 40, 14, 26, 33, 43, 1, 28, 47, 9, 26, 30, 34, 23, 6, 16, 7, 56}
returns 1.
Step 3 - Return the relative position of an item in an array
INDEX(A2:A26,MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0))
MATCH(lookup_value;lookup_array; [match_type]) returns the relative position of an item in an array that matches a specified value
MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0)
becomes
MATCH(1, {40, 34, 36, 19, 23, 5, 40, 14, 26, 33, 43, 1, 28, 47, 9, 26, 30, 34, 23, 6, 16, 7, 56}, 0)
returns 12.
Step 4 - Return a value or reference of the cell at the intersection of a particular row and column
INDEX(array,row_num,[column_num]) returns a value or reference of the cell at the intersection of a particular row and column, in a given range
INDEX(A2:A26,MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0))
becomes
INDEX(A2:A26,12)
and returns 42.
EDIT: Added excel workbook to this blog post
Download excel example file
find-closest-value.xls
(Excel 97-2003 Workbook *.xls)
How to find closest values
Array formula in cell C4:
How to create an array formula
- Select cell C4
- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar.
- Press and hold Ctrl + Shift.
- Press Enter once
- Release all keys
How to copy array formula
- Select cell C4
- Copy cell c4 (Ctrl + c)
- Select cell range C4:C20
- Paste (Ctrl + v)
Download excel file
How to find closest values and return adjacent values
Array formula in cell D5:
Array formula in cell E5:
How to create an array formula
- Select cell D5
- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar.
- Press and hold Ctrl + Shift.
- Press Enter once
- Release all keys
How to copy array formula
- Select cell D5
- Copy (Ctrl + c)
- Select cell range D6:D28
- Paste (Ctrl + v)
Download excel example file
find-closest-values-return-adjacent-value.xlsx
Functions:
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
ABS(number)
Returns the absolute value of a number, a number without its sign.
MATCH(lookup_value;lookup_array; [match_type])
Returns the relative position of an item in an array that matches a specified value
MIN(number1,[number2])
Returns the smallest number in a set of values. Ignores logical values and text









May 2nd, 2009 at 9:35 pm
looks like B.S. and does not work.
May 3rd, 2009 at 8:49 am
To prove that the formula works I have uploaded an excel workbook with the exact same values and formula as in this blog post.
Maybe you forgot to press CTRL + SHIFT + ENTER after you typed the formula?
August 13th, 2009 at 8:38 pm
It works, comment one needs to learn how to do their own work...
before calling BS on A CORRECT FORMULA.
Thank you for the help on this forumula this is exaclty what i was looking for
August 20th, 2009 at 9:20 am
Could someone help me use this formula in German? Using excel in a different in language is kinda challenging =D
August 20th, 2009 at 11:38 am
Translate excel functions from english to german: http://www.piuha.fi/excel-function-name-translation/index.php?page=deutsch-english.html
September 4th, 2009 at 9:55 pm
In the formula there are some colons (,) that should be semi-colons (;) if I am right;
--> =INDEX(A2:A26;MATCH(MIN(ABS(A2:A26-C1));ABS(A2:A26-C1);0))
September 4th, 2009 at 10:29 pm
hey,
I think that has to do with your regional settings. See this post: http://www.get-digital-help.com/2007/11/08/excel-regional-settings/
April 30th, 2010 at 8:20 pm
Junk... Does not work
April 30th, 2010 at 9:38 pm
James,
Send me your excel file (without sensitive data) and I´ll see what I can do: http://www.get-digital-help.com/contact/
July 6th, 2010 at 2:57 am
Hey, I don't know if this is specific to Excel 2010, however I found an error in your equation when attempting this in excel 2010, here is the corrected version of the equation:
=INDEX(D5:D36,MATCH(MIN(ABS(D5:D35-W8)),ABS(D5:D35-W8),0),0)
July 8th, 2010 at 12:56 pm
Ben Personick,
Your formula contains two different cell references, D5:D36 and D5:D35. What if the closest value is in cell D36?
August 22nd, 2010 at 7:58 am
Just a Typo. should have been D35 in each, D36 is blank.
Here it is using your original cell ranges instead:
=INDEX(A2:A26,MATCH(MIN(ABS(A2:A26-C1)),ABS(A2:A26-C1),0),0)
Hope that makes it clearer.
In excel 2010, an index can have two dimensions, and you must have a numerical value for both.
August 24th, 2010 at 9:54 pm
Ben Personick,
Thanks!
September 4th, 2010 at 1:06 pm
I want to find the two closest values (one above and one below) to my search value.
I would like a function that will perform this automatically as data is entered in to the search value cell.
The cntl+shift+enter is not a good solution for my spreadsheet. I need to see the results as the user enters the data and without any special key combinations.
September 5th, 2010 at 9:36 am
Update.
Found two good solutions:
The first:
To find the closest larger number or an exact match in column A, use the SMALL and COUNTIF functions as shown in the following formula:
=SMALL($A$2:$A$7,COUNTIF($A$2:$A$7,"< "&B2)+1)
To find the closest smaller number or an exact match in column A, use the LARGE and COUNTIF functions as shown in the following formula:
=LARGE($A$2:$A$7,COUNTIF($A$2:$A$7,">"&B2)+1)
(http://www.exceltip.com/st/Retrieving_the_Closest_Larger_/_Closest_Smaller_Values_from_a_List_when_there_is_No_Exact_Match)/993.html)
It worked a treat, and then this solution from Eng-tips:
The second:
A1 is the search value. A2 to A11 the array and A12 and A13 the nearest values below and above:
In B1 put =MATCH(A1,A2:A11)
In A12 put =INDEX($A$2:$A$11,$B$1)
In A13 put =INDEX($A$2:$A$11,$B$1+1)
(http://eng-tips.com/viewthread.cfm?qid=280609&page=1)
To go one step further and choose the value closest to the search value is a simple IF statement:
{=IF((A1-A12)<(A13-A1),A12,A13)}
September 5th, 2010 at 11:20 am
Note: The first of the two solutions works with unsorted data and the second using the MATCH function, with ordered data.
January 16th, 2011 at 9:03 am
Hi,
The solution was veryvery helpful. Thanks for that!
However, facing a problem with decimal values.
I have a data say :: {C3:C5}{0.456,0.567,.678}
Data enterd in D1 cell : {0.560}
When trying to find out the closest value for it, the formula entered is :
=INDEX(C3:C5,MATCH(MIN(ABS(C3:C5-D1)),ABS(C3:C5-D1),0))
The value returned is always the first value from C3 i.e. 0.456.
Is there something i am missing out on???
January 16th, 2011 at 7:14 pm
Pradnya.Karmarkar,
I tried your example and the value returned here is 0,567. Maybe you forgot CTRL + SHIFT + ENTER?
March 2nd, 2011 at 4:24 am
Fantastic! Excellent Thank you
March 2nd, 2011 at 10:14 am
You are welcome!! Thanks for commenting!
March 15th, 2011 at 12:11 am
Thanks, exactly what I needed
March 15th, 2011 at 9:25 am
Hi,
Yes, now the example works. My cell given was wrong.
Thanks a lot !!!
March 17th, 2011 at 9:12 am
Penny and Pradnya Karmarkar,
thanks for commenting!
April 1st, 2011 at 1:52 pm
Thanks for this.
Just in case others are as stupid as me:
It took me a while to figure out you need to press Ctrl SHIFT ENTER after typing (or pasting) the formula. Ctrl SHIFT ENTER is not part of the formula....
April 1st, 2011 at 7:48 pm
Stein,
Thanks!
I have edited this post and tried to explain how to create an array formula.
April 17th, 2011 at 6:50 pm
Thanks, this worked perfect after figuring out ctrl+shift+enter. Genious!
May 28th, 2011 at 2:36 am
excellent tips. thanks for the help Oscar.
May 30th, 2011 at 7:45 am
eben,
you are welcome!
July 24th, 2011 at 11:59 am
Brilliant example - very many thanks.
July 25th, 2011 at 9:42 am
Richard Moore,
Thank you for commenting!!
July 28th, 2011 at 4:55 pm
Excellent solution! Thanks a lot for this elegant tip...
July 29th, 2011 at 10:05 am
Anurag,
Thanks!!
September 8th, 2011 at 9:25 am
Excellent...
September 27th, 2011 at 7:26 am
Thanks for sharing!
It did not work until I used CMD+SHIFT+ENTER (on a mac).
October 27th, 2011 at 9:41 pm
This looks like something I could use - I'm comparing two worksheets of school names and I need to get the closest match from to the other. Can this formula be altered to search in text strings? Thx
October 27th, 2011 at 9:43 pm
Hopefully, yes?
October 31st, 2011 at 9:19 am
Jenna,
No, it can´t but maybe these blog posts can help you out:
http://www.get-digital-help.com/2011/04/04/excel-udf-fuzzy-lookups/
http://www.get-digital-help.com/2011/03/24/fuzzy-vlookup-excel-array-formula/
November 24th, 2011 at 2:33 pm
Hi,
I like the look of the formula and I have played around with the spreadsheet you updloaded but I cant get ABS to return multiple values. This is the problem I think people have been having. I have tried pasting your formula (ctrl+shift+enter) and rejig the cell references to suit my needs but I cant seem to get it to work. I worked through it with the evaluate function and the ABS function was returning a single value whereas with your it returns them all. How do I make it do this?
November 29th, 2011 at 1:20 pm
Anyone who is having trouble with this, research array formulas.
http://office.microsoft.com/en-us/excel-help/introducing-array-formulas-in-excel-HA001087290.aspx
There is a section that states you have to select all the cells that it applies to.
November 30th, 2011 at 11:15 am
heath,
I have added a new section "How to find closest values" to this blog post. Check it out, I believe it answers your question.
December 15th, 2011 at 1:01 pm
execellent formula, thank you! i need some extra help though. i would like to return values corresponding to the nearest value.
For example, my data set is in column C and i returned the value nearest to what i was looking for; and found it to be in C6 for example. But i would also like to return the corresponding value in cell A6. Is there any way to do this?
Thanks again,
Cormac
December 19th, 2011 at 12:59 pm
Cormac,
read this: Find closest values and return adjacent values
January 18th, 2012 at 8:15 am
THANK YOU VERY MUCH!
This really helps