Excel MATCH + COUNTIF function: retrieving the nth value in an array

krumholz picture krumholz · Apr 10, 2012 · Viewed 18.8k times · Source

I have a formula that I'm using in Excel to return the row # of the first item that matches a specified value.

Formula: =MATCH(0,COUNTIF($B$1,List),0) + CTRL + SHIFT + ENTER and in Mac: CMD + RETURN

Becomes:

MATCH(0,{**0**;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0},0)

Outputs: 1

I would like to update the function so that I can find the 2nd, 3rd, etc. instance that matches the specified value.

Like This:

MATCH(0,{0;**0**;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0},0)

And this outputs: 2

Answer

barry houdini picture barry houdini · Apr 10, 2012

Doesn't your current formula find the position of the first value in list that doesn't match B1?

For 2nd try this array formula

=SMALL(IF(List<>$B$1,ROW(List)-MIN(ROW(List))+1),2)

replace the 2 with any value n for nth match. Assumes List is a single column