Transform comma separated ID's into comma separated Names in Excel 2007/10 using lookup table

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
351
Office Version
  1. 2010
Platform
  1. Windows
I'm trying to match comma separated ID Data to the LOOKUP table and return the NAMEs of the IDs also as comma separated. The last column shows what the required output should look like, and the Current Formula Name Output is the results I have from my formula, which is working correctly.

- Note that if there is no such ID it should just ignore it as in S4.
- The IDs can vary up to 10 characters in length and contain symbols
- The Name can be up to 256 characters in length
- The amount of comma separated ID's in the DATA column cells can be up to 100.

I'm basically trying to transform the ID DATA into each of the LOOKUP NAMES

The solution can be in either VBA or an Excel formula, whichever is easier. I'm not very good at either, but my formula is the best I have come up with, although you can see it has problems with missing ID's and only checks 3 ID's.

My current formula that isn't working:=VLOOKUP(TRIM(LEFT(SUBSTITUTE(D2,",",REPT(" ",20)),20)),$A$2:$B$8,2,FALSE)&","&VLOOKUP(TRIM(MID(SUBSTITUTE(D2,",",REPT(" ",20)),20,20)),$A$2:$B$8,2,FALSE)&","&VLOOKUP(TRIM(RIGHT(SUBSTITUTE(D2,",",REPT(" ",20)),20)),$A$2:$B$8,2,FALSE)

Any help would be most appreciated to achieve the required output result.

Example table below
LOOKUP IDLOOKUP NAME*ID DATACurrent Formula NAME OUTPUTRequired NAME OUTPUT
S2ABCDE*S2,S6,S7,S4,S3ABCDE,ADE,ABABCDE,ADE,AB
S3AB*G2,S4#N/A#N/A
S6ADE*G9,S6,G2,S3GPES,ADE,ABGPES,ADE,AB
S7!TE*G2,G9D,GPES,GPESD,GPES,GPES
G2D*G2#N/A#N/A
G9GPES*S2,G9ABCDE,GPES,GPESABCDE,GPES,GPES
&ALLALL*&ALL#N/A#N/A
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Why isn't S7 matched with ITE in the first row of your example? Numerous others are confusing.
 
Upvote 0
The output result was completely wrong, as I have been trying all sorts of things to get this working and forgot to amend it when posted. Here is the correct output.
LOOKUP IDLOOKUP NAME*ID DATAFormula NAME OUTPUTRequired NAME OUTPUT
S2ABCDE*S2,S6,S7,S4,S3ABCDE,ADE,ABABCDE,ADE, !TE, AB
S3AB*G2,S4#N/AD
S6ADE*G9,S6,G2,S3GPES,ADE,ABGPES,ADE,D,AB
S7!TE*G2,G9D,GPES,GPESD,GPES
G2D*G2#N/AD
G9GPES*S2,G9ABCDE,GPES,GPESABCDE,GPES
&ALLALL*&ALL#N/AALL
 
Upvote 0
How about this macro?
Code:
Sub SplitNames()
Dim ID() As String, REQ As String, r As Variant, i As Long, j As Long, LR As Long, ub As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row
Err.Clear
For i = 2 To LR
  ID = Split(Range("D" & i), ",")
  ub = UBound(ID())
    For j = 0 To ub
    On Error Resume Next
    r = Application.WorksheetFunction.VLookup(ID(j), Range("A2:B" & LR), 2, False)
    If Err.Number = 0 Then REQ = REQ & r & ","
    Next j
   Cells(i, 5) = Left(REQ, Len(REQ) - 1)  ' Result in column E
   REQ = ""
Next i
End Sub
 
Upvote 0
Solution
WOW!! That's it.

Thank you so much for your help with this. I was getting extremely lost and getting no where fast.
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,094
Members
452,542
Latest member
Bricklin

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