Finding nth occurrence of a value

rigreene

New Member
Joined
Sep 17, 2014
Messages
4
I want to be able to find the nth value using VLOOKUP, INDEX, or something similar.

Example:

=VLOOKUP(2,A1:B5,2,0)
would return "Blue"

[TABLE="width: 200"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]Green[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]4[/TD]
[TD]Green[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]2[/TD]
[TD]Red[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]5[/TD]
[TD]Red[/TD]
[/TR]
</tbody>[/TABLE]

But, if I want it to find the 2nd "2" so that it returns "Red," how would I go about that?

Thanks!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi.

I notice that link appears to be a UDF solution. If you want a purely formula-based solution, use this array formula**:

=INDEX(B1:B5,SMALL(IF(A1:A5=C1,ROW(A1:A5)-MIN(ROW(A1:A5))+1),k))

where C1 holds the search value, e.g. 2, and k at the end should be replaced with a number representing which occurrence of that search value you wish to return, e.g. 1=1st, 2=2nd, etc.

Regards


**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
 
Upvote 0
Hi,

if you are using Excel 2010 (or newer versions ) you could give a chance to a standard formula

=IFERROR(INDEX($B$1:$B$5,AGGREGATE(15,6,ROW($A$1:$A$5)/($A$1:$A$5=2),ROW(A1))),"")

copying down the formula you get all the occurences

If it's of any help.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top