Quick, clean, and to the point

Get nth match

Excel formula: Get nth match
Generic formula 

To get the position of the nth match (for example, the 2nd matching value, the 3rd matching value, etc.), you can use a formula based on the SMALL function. In the example shown, the formula in G5 is:


This formula returns the position of the second occurrence of "red" in the list.

Note: this is an array formula and must be entered with control + shift + enter.


This formula uses the named range "list" which is the range B5:B11.

The core of this formula is the SMALL function, which simply returns the nth smallest value in a list of values that correspond to row numbers. The row numbers have been "filtered" by the IF statement, which applies the logic for a match. Working from the inside out, IF compares all values in the named range "list" to the value in B5, which creates an array like this:


The "value if true" is a set of relative row numbers created by this code:


The result is an array like this:


See this page for a full explanation.

With a logical test that returns an array of results, the IF function acts as a filter – only row numbers that correspond to a match survive, the rest return FALSE. The result returned by IF looks like this:


The numbers 1, 5, and 7 correspond to the location of "red" in the list.

Finally, SMALL returns the nth smallest item in this list, ignoring FALSE values. In the example, F5 contains 2, so SMALL returns the 2nd smallest value: 5.

Get associated value

Once you have the relative position of the nth match, you can use that position with the INDEX function to return an associated value.

Dave Bruns

Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

Download 100+ Important Excel Functions

Get over 100 Excel Functions you should know in one handy PDF.

Excel foundational video course
Excel Pivot Table video training course
Excel formulas and functions video training course
Excel Charts video training course
Video training for Excel Tables
Dynamic Array Formulas