VLookup when I know there are multiple matches (and I need them all)

TheRedCardinal

Active Member
Joined
Jul 11, 2019
Messages
252
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have a sheet (Sheet 1) with a column that contains numerical employee IDs. Each employee has a single row.

I have another sheet (Sheet 2) that lists those IDs and contains project supervisors. Some employees have more than one supervisor. Where this is the case, the employee is listed in multiple (successive) rows, with the same ID, but the name of the supervisor varying.

I need to create 4 columns (that is the maximum number of supervisors) in Sheet 1, and lookup the names of all possible supervisors, sometimes 1, sometimes as many as 4.

I have some success with this by doing the following:

  1. Creating a "helper column" in sheet 2 that uses a simple rolling COUNTIF formula to add an appending -1, -2, -3 or -4 to the employee ID
  2. Calling my column headers Supervisor 1, Supervisor 2 etc in Sheet 1
  3. Using Vlookup to lookup [ EmployeeID & "-" & Right(ColumnHeader,1)] in Sheet 2
This is working find except that for presentation purposes, I need the primary supervisor, who is always listed first, in Supervisor 1 column, and unfortunately the way the COUNTIF cheat is working means that for mulitple supervisors, they are ranked in reverse order.

I have written VBA code to do this but the user is not keen on it and would prefer a formula for future use.

Can this be done?
 
Sorry I think I've worked it out now.

I selected G2:N2, put in the formula and then did the array enter - and it now looks ok (but I'm testing).

Then I dragged down to the bottom.

Looks good!

But is there a way to get rid of n/a when it doesn't match?

I tried this:

=IFERROR(TOROW(FILTER(Data!$AA$2:$AB$2597,Data!$K$2:$K$2597=Students!A958)),"")

But I still get "n/a" when I enter it


 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Amazing thanks Fluff.

This looks like something I'll need to learn as it looks incredible.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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