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

TheRedCardinal

Board Regular
Joined
Jul 11, 2019
Messages
243
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?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Done!
 
Upvote 0
Thanks for that. (y)
How about something like
Excel Formula:
=TRANSPOSE(FILTER(Sheet1!B2:B100,Sheet1!A2:A100=A2))
 
Upvote 0
Not quite, but I think there must be an error in your formula (you don't mention sheet 2?)

For context, here are the data fields:

Sheet 1 - Employee ID in column A
Supervisor 1 First Name in G
Supervisor 1 Second Name in H
As above through to Supervisor 4 Last Name in Column N

Sheet 2 - Employee ID in column K
Supervisor First Name in column AA
Supervisor second name in Column AB

Thanks again for looking!
 
Upvote 0
As you gave no real information I just posted a very generic formula.

Can you post some sample data of what you have & expected results.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Thanks Fluff - sorry I hope I didn't come across as rude and ungrateful! I was writing the OP without access to the database so I was keeping it vague.

Anyway....

Here's what it should look like:

HUMS PGRs for AR Log.xlsx
ABCDEFGHI
1Person IDSupervisor 1 First NameSupervisor 1 Last NameSupervisor 2 First NameSupervisor 2 Last NameSupervisor 3 First NameSupervisor 3 Last NameSupervisor 4 First NameSupervisor 4 Last Name
210079018MrFluffPeterRabbitDr ShrekVihratKohli
310083293Mr FluffMoSalah
410083997CharlesDickens
510094649CharlesDickens
610120682SuperManBoJangles
710248826JamesHetfield
Sample Employees
Cell Formulas
RangeFormula
B2:C2B2='Sample Data'!B2
D2:E2D2='Sample Data'!B3
F2:G2F2='Sample Data'!B4
H2:I2H2='Sample Data'!B5
B3:C3B3='Sample Data'!B6
D3:E3D3='Sample Data'!B7
B4:C6B4='Sample Data'!B8
D6:E6D6='Sample Data'!B11
B7:C7B7='Sample Data'!B12


And here is what the supervisor data looks like:

HUMS PGRs for AR Log.xlsx
ABC
1Person IDSupervisor 1st NameSupervisor 2nd Name
210079018MrFluff
310079018PeterRabbit
410079018Dr Shrek
510079018VihratKohli
610083293Mr Fluff
710083293MoSalah
810083997CharlesDickens
910094649CharlesDickens
1010120682SuperMan
1110120682BoJangles
1210248826JamesHetfield
Sample Data


Obviously these column headers are different but just to give you a feeling for the data.
 
Upvote 0
Thanks for that.
How about, for 365 only
Fluff.xlsm
ABCDEFGHI
1Person IDSupervisor 1 First NameSupervisor 1 Last NameSupervisor 2 First NameSupervisor 2 Last NameSupervisor 3 First NameSupervisor 3 Last NameSupervisor 4 First NameSupervisor 4 Last Name
210079018MrFluffPeterRabbitDr ShrekVihratKohli
310083293Mr FluffMoSalah
410083997CharlesDickens
510094649CharlesDickens
610120682SuperManBoJangles
710248826JamesHetfield
8
Sheet2
Cell Formulas
RangeFormula
B2:I2,B7:C7,B6:E6,B4:C5,B3:E3B2=TOROW(FILTER('Sample Data'!$B$2:$C$100,'Sample Data'!$A$2:$A$100=A2))
Dynamic array formulas.
 
Upvote 0
Hey fluff I am not sure how to use that?
This is what I've placed in G2 (which is the first name, of Supervisor 1):

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

But what do I do next sorry!?
 
Upvote 0
What happened when you did that?
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,048
Members
449,206
Latest member
Healthydogs

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