VLOOKUP For Multiple Matches

srj1359

New Member
Joined
Mar 5, 2015
Messages
46
Office Version
  1. 2016
Platform
  1. Windows
Hello!

I have two sheets (Titles and Accounts).

The Accounts sheet has two columns: Participant Name (column A) and PRODUCT_ID (column B).

The Titles sheet has 32 columns, but the only one that matters is PRODUCT_ID (column AF).

In the Accounts sheet, multiple participants can have the same product ID.

In the Titles sheet, multiple titles can have the same product ID.

I'm trying to find a way to search to pull in the multiple participant names that match each product ID and the only way I think of is a VLOOKUP (though I'm open to other suggestions).

Please let me know if I need to clarify anything.

If it helps, I work in publishing, so think of it in terms of customer A bought a Science bundle and a History bundle. Customer B only bought a Science bundle. Each bundle has multiple books in it. How can I find out how many titles customer A has and how many customer B has?

Thank you in advance. I have been searching and trying different ideas for hours and would so appreciate some help from someone with more knowledge than me :)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this with a copy of your workbook.

VBA Code:
Sub CollectNames()
  Dim d As Object
  Dim a As Variant
  Dim i As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  With Sheets("Accounts")
    a = .Range("A2", .Range("B" & Rows.Count).End(xlUp)).Value
  End With
  For i = 1 To UBound(a)
    d(a(i, 2)) = d(a(i, 2)) & ";" & a(i, 1)
  Next i
  With Sheets("Titles")
    a = .Range("AF2", .Range("AF" & Rows.Count).End(xlUp)).Value
    For i = 1 To UBound(a)
      a(i, 1) = Mid(d(a(i, 1)), 3)
    Next i
    With .Range("AG2").Resize(UBound(a))
      .Value = a
      .TextToColumns DataType:=xlDelimited, Semicolon:=True, Comma:=False, Space:=False, Other:=False
    End With
  End With
End Sub

Results for me from your sample data:

srj1359.xlsm
AAFAGAH
1publication_titlePRODUCT_ID
2In Search of Lost Time by Marcel ProustAAA-00001BC UniversityDEF University
3Ulysses by James JoyceAAA-00002BC UniversityDEF University
4Don Quixote by Miguel de CervantesAAA-00003BC UniversityDEF University
5The Great Gatsby by F. Scott FitzgeraldAAA-00004BC UniversityDEF University
6One Hundred Years of Solitude by Gabriel Garcia MarquezAAA-00005BC UniversityDEF University
7Moby **** by Herman MelvilleZZZ-00001EF University
8War and Peace by Leo TolstoyZZZ-00002EF University
9Lolita by Vladimir NabokovZZZ-00003EF University
10Hamlet by William ShakespeareZZZ-00004EF University
11The Catcher in the Rye by J. D. SalingerZZZ-00005EF University
12The Odyssey by HomerAAA-00001BC UniversityDEF University
13The Brothers Karamazov by Fyodor DostoyevskyAAA-00002BC UniversityDEF University
14Crime and Punishment by Fyodor DostoyevskyAAA-00003BC UniversityDEF University
15Madame Bovary by Gustave FlaubertAAA-00004BC UniversityDEF University
16The Divine Comedy by Dante AlighieriAAA-00005BC UniversityDEF University
17The Adventures of Huckleberry Finn by Mark TwainZZZ-00001EF University
18Alice's Adventures in Wonderland by Lewis CarrollZZZ-00002EF University
19Pride and Prejudice by Jane AustenZZZ-00003EF University
20Wuthering Heights by Emily BrontëZZZ-00004EF University
21To the Lighthouse by Virginia WoolfZZZ-00005EF University
Titles
 
Upvote 0
@Peter_SSs I think this should work, except it's cutting off the first letter of the first participant name (in your example above notice in AG it says "BC University" instead of "ABC University." Can you please tell me how to fix this?
 
Upvote 0
Here is a PQ solution

Bring both tables into the PQ editor and join them

Power Query:
let
    Source = Table.NestedJoin(Table1, {"PRODUCT_ID"}, Table2, {"PRODUCT_ID"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"publication_title"}, {"Table2.publication_title"})
in
    #"Expanded Table2"

Book2
ABC
1Participant NamePRODUCT_IDTable2.publication_title
2ABC UniversityAAA-00001In Search of Lost Time by Marcel Proust
3ABC UniversityAAA-00001The Odyssey by Homer
4DEF UniversityAAA-00001In Search of Lost Time by Marcel Proust
5DEF UniversityAAA-00001The Odyssey by Homer
6ABC UniversityAAA-00002Ulysses by James Joyce
7ABC UniversityAAA-00002The Brothers Karamazov by Fyodor Dostoyevsky
8DEF UniversityAAA-00002Ulysses by James Joyce
9DEF UniversityAAA-00002The Brothers Karamazov by Fyodor Dostoyevsky
10ABC UniversityAAA-00003Don Quixote by Miguel de Cervantes
11ABC UniversityAAA-00003Crime and Punishment by Fyodor Dostoyevsky
12DEF UniversityAAA-00003Don Quixote by Miguel de Cervantes
13DEF UniversityAAA-00003Crime and Punishment by Fyodor Dostoyevsky
14ABC UniversityAAA-00004The Great Gatsby by F. Scott Fitzgerald
15ABC UniversityAAA-00004Madame Bovary by Gustave Flaubert
16DEF UniversityAAA-00004The Great Gatsby by F. Scott Fitzgerald
17DEF UniversityAAA-00004Madame Bovary by Gustave Flaubert
18ABC UniversityAAA-00005One Hundred Years of Solitude by Gabriel Garcia Marquez
19ABC UniversityAAA-00005The Divine Comedy by Dante Alighieri
20DEF UniversityAAA-00005One Hundred Years of Solitude by Gabriel Garcia Marquez
21DEF UniversityAAA-00005The Divine Comedy by Dante Alighieri
22DEF UniversityZZZ-00001Moby **** by Herman Melville
23DEF UniversityZZZ-00001The Adventures of Huckleberry Finn by Mark Twain
24DEF UniversityZZZ-00002War and Peace by Leo Tolstoy
25DEF UniversityZZZ-00003Lolita by Vladimir Nabokov
26DEF UniversityZZZ-00004Hamlet by William Shakespeare
27DEF UniversityZZZ-00005The Catcher in the Rye by J. D. Salinger
28DEF UniversityZZZ-00002Alice's Adventures in Wonderland by Lewis Carroll
29DEF UniversityZZZ-00003Pride and Prejudice by Jane Austen
30DEF UniversityZZZ-00004Wuthering Heights by Emily Brontë
31DEF UniversityZZZ-00005To the Lighthouse by Virginia Woolf
Sheet4
 
Upvote 0
Additionally, if you like Peter's presentation then using the data in the above post, you can create a Power Pivot as follows

Book2
AB
3Table2.publication_titleSchool
4Alice's Adventures in Wonderland by Lewis CarrollDEF University
5Crime and Punishment by Fyodor DostoyevskyABC University, DEF University
6Don Quixote by Miguel de CervantesABC University, DEF University
7Hamlet by William ShakespeareDEF University
8In Search of Lost Time by Marcel ProustABC University, DEF University
9Lolita by Vladimir NabokovDEF University
10Madame Bovary by Gustave FlaubertABC University, DEF University
11Moby **** by Herman MelvilleDEF University
12One Hundred Years of Solitude by Gabriel Garcia MarquezABC University, DEF University
13Pride and Prejudice by Jane AustenDEF University
14The Adventures of Huckleberry Finn by Mark TwainDEF University
15The Brothers Karamazov by Fyodor DostoyevskyABC University, DEF University
16The Catcher in the Rye by J. D. SalingerDEF University
17The Divine Comedy by Dante AlighieriABC University, DEF University
18The Great Gatsby by F. Scott FitzgeraldABC University, DEF University
19The Odyssey by HomerABC University, DEF University
20To the Lighthouse by Virginia WoolfDEF University
21Ulysses by James JoyceABC University, DEF University
22War and Peace by Leo TolstoyDEF University
23Wuthering Heights by Emily BrontëDEF University
Sheet5


See this link for how to do it: Excel: Reporting Text in a Pivot Table - Strategic Finance
 
Upvote 0
I think this should work, except it's cutting off the first letter of the first participant name
Yes, sorry, I changed one part of my code and forgot to change another corresponding part.

Try making this change to the code.
Rich (BB code):
a(i, 1) = Mid(d(a(i, 1)), 3)
a(i, 1) = Mid(d(a(i, 1)), 2)
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

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