VLookup Index Match first, second, third

Mark F

Well-known Member
Joined
Jun 7, 2002
Messages
513
Office Version
  1. 365
Platform
  1. Windows
I have a sheet called "Top 100" where I want to vlookup or index match data from a sheet called "USCOTRN"

On the "Top 100" sheet, I want to find first appearance of the value that is in $B4 in Column A on "USCOTRN" sheet and display the value that is in Column F on "USCOTRN" sheet display in column BC (first cell is BC4) on the "Top 100" sheet

On the "Top 100" sheet, I want to find first appearance of the value that is in $B4 in Column A on "USCOTRN" sheet and display the value that is in Column D on "USCOTRN" sheet display in column BD (first cell is BD4) on the "Top 100" sheet

On the "Top 100" sheet, I want to find the second appearance (if there is one) of the value that is in $B4 in Column A on "USCOTRN" sheet and display the value that is in Column D on "USCOTRN" sheet display in column BE(first cell is BE4) on the "Top 100" sheet

On the "Top 100" sheet, I want to find second appearance of the value that is in $B4 in Column A on "USCOTRN" sheet and display the value that is in Column F on "USCOTRN" sheet display in column BD (first cell is BF4) on the "Top 100" sheet

If there are more than two appearance in Column A, id like to use columns BG onwards

I have tried with the code below, but not really getting anywhere, and not fully understanding how to get it to work
Code:
=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$f$5:$f$1000=B4,ROW(USCOTRN!$f$5:$f$1000)-ROW(USCOTRN!A5)+1),1))

I'd appreciate any help to point me in the right direction

Thanks
Mark :)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$f$5:$f$1000=B4,ROW(USCOTRN!$f$5:$f$1000)-ROW(USCOTRN!A5)+1),1))

The 1 at the end tells small to return the 1st, you need to tell it to return the 1st 2nd 3rd etcso

=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$f$5:$f$1000=B4,ROW(USCOTRN!$f$5:$f$1000)-ROW(USCOTRN!A5)+1),row(A1))
 
Last edited:
Upvote 0
=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$f$5:$f$1000=B4,ROW(USCOTRN!$f$5:$f$1000)-ROW(USCOTRN!A5)+1),1))

The 1 at the end tells small to return the 1st, you need to tell it to return the 1st 2nd 3rd etcso

=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$f$5:$f$1000=B4,ROW(USCOTRN!$f$5:$f$1000)-ROW(USCOTRN!A5)+1),row(A1))


Thanks

I've tried that formula, and Excel suggests there is an error in the formula and gives an amendment
=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$F$5:$F$1000=B4,ROW(USCOTRN!$F$5:$F$1000)-ROW(USCOTRN!A5)+1),ROW(A1)))

This gives a #VALUE! error

Any ideas? :)

Mark
 
Upvote 0
The change is because i missed a bracket off the end, try

=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$F$5:$F$1000=B4,ROW(USCOTRN!$F$5:$F$1000)-ROWS(USCOTRN!$A$1:$A$4)),ROW(A1)))
 
Last edited:
Upvote 0
The change is because i missed a bracket off the end, try

=INDEX(USCOTRN!$A$5:$D$1000,SMALL(IF(USCOTRN!$F$5:$F$1000=B4,ROW(USCOTRN!$F$5:$F$1000)-ROWS(USCOTRN!$A$1:$A$4)),ROW(A1)))

Thanks. That's the change it made, but still coming up as a #NUM! error

Could you advise me on why "ROWS(USCOTRN!$A$1:$A$4))" - to help me understand a bit more

Have I got the ranges right, or something else to think about?

 
Upvote 0
Just re-read your 1st post, the ranges are wrong -

=INDEX(USCOTRN!$F$5:$F$1000,SMALL(IF(USCOTRN!$A$5:$A$1000=B4,ROW(USCOTRN!$F$5:$F$1000)-ROWS(USCOTRN!$A$1:$A$4)),ROW(A1)))

The index range is what you want returning, match should match B4 to col A. You will need to change the index range to give you 1st, 2nd for each column you want to return.

The
ROWS(USCOTRN!$A$1:$A$4)) compensates for the number of rows that are missing from the index/match range, in this case your data starts on row 5 so we adjust by 4 rows.
 
Upvote 0
Just re-read your 1st post, the ranges are wrong -

=INDEX(USCOTRN!$F$5:$F$1000,SMALL(IF(USCOTRN!$A$5:$A$1000=B4,ROW(USCOTRN!$F$5:$F$1000)-ROWS(USCOTRN!$A$1:$A$4)),ROW(A1)))

The index range is what you want returning, match should match B4 to col A. You will need to change the index range to give you 1st, 2nd for each column you want to return.

The
ROWS(USCOTRN!$A$1:$A$4)) compensates for the number of rows that are missing from the index/match range, in this case your data starts on row 5 so we adjust by 4 rows.

Bingo! Sorted :)

Thanks so much for your help on this :)

Now that I've got this, I do have another stage which involves VBA...finding the last row (LR) in column A in Top 200, and using "LR" instead of the "1000". I can do the VBA for finding the LR, but tweaking the code below for "LR" is a little beyond me

Code:
LR= Range("a" & Rows.Count).End(xlUp).Row
Range("BC4").Select
    Selection.FormulaArray = _
        "=IF(ISERROR(INDEX(USCOTRN!R5C6:R10000C6,SMALL(IF(USCOTRN!R5C1:R10000C1=RC2,ROW(USCOTRN!R5C6:R10000C6)-ROWS(USCOTRN!R1C1:R4C1)),ROW(R1C1)))),0,INDEX(USCOTRN!R5C6:R10000C6,SMALL(IF(USCOTRN!R5C1:R10000C1=RC2,ROW(USCOTRN!R5C6:R10000C6)-ROWS(USCOTRN!R1C1:R4C1)),ROW(R1C1))))"
Mark
 
Upvote 0
You're welcome, unfortunately i'm not good with vb, hopefully someone else will jump in.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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