To find the closest match in numeric data, you can use INDEX and MATCH, with help from the ABS and MIN functions. In the example shown, the formula in F5, copied down, is:


where trip (B5:B14) and cost (C5:C14) are named ranges.

In F5, F6, and F7, the formula returns the trip closest in cost to 500, 1000, and 1500, respectively.

Note: this is an array formula and must be entered with control + shift + enter, except in Excel 365.

Generic formula



At the core, this is an INDEX and MATCH formula: MATCH locates the position of the closest match, feeds the position to INDEX, and INDEX returns the value at that position in the Trip column. The hard work is done with the MATCH function, which is carefully configured to match the "minimum difference" like this:


Taking things step-by-step, the lookup value is calculated with MIN and ABS like this:


First, the value in E5 is subtracted from the named range cost (C5:C14). This is an array operation, and since there are 10 values in the range, the result is an array with 10 values like this:


These numbers represent the difference between each cost in C5:C15 and the cost in cell E5, 700. Some values are negative because a cost is lower than the number in E5. To convert negative values to positive values, we use the ABS function:


which returns:


We are looking for the closest match, so we use the MIN function to find the smallest difference, which is 101:

MIN({899;199;250;201;495;1000;450;101;500;795}) // returns 101

This becomes the lookup value inside MATCH. The lookup array is generated as before:

ABS(cost-E5) // generate lookup array

which returns the same array we saw earlier:


We now have what we need to find the position of the closest match (smallest difference), and we can rewrite the MATCH portion of the formula like this:

MATCH(101,{899;199;250;201;495;1000;450;101;500;795},0) // returns 8

With 101 as the lookup value, MATCH returns 8, since 101 is in the 8th position in the array. Finally, this position is fed into INDEX as the row argument, with the named range trip as the array:


and INDEX returns the 8th trip in the range, "Spain". When the formula is copied down to cells F6 and F7, it finds the closest match to 1000 and 1500, "France" and "Thailand" as shown.

Note: if there is a tie, this formula will return the first match.


The XLOOKUP function provides an interesting way to solve this problem, because a match type of 1 (exact match or next largest) or -1 (exact match or next smallest) doesn't require data to be sorted. This means we can write a formula like this:


As above, we use the absolute value of (cost-E5) to create a lookup array:


Then we configure XLOOKUP to look for zero, with match type set to 1, for exact match or next largest. We supply the named range trip as the return array, so the result is "Spain" as before.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.