lookup by comma delimited list with single value list

cerchiarax

New Member
Joined
Jan 29, 2016
Messages
20
Hi guys,

I've been trying to get a solution my self and I searched the thread and found the following below that partially got what I was after.

https://www.mrexcel.com/forum/excel-questions/546013-find-value-cell-comma-delimited-list.html


https://www.mrexcel.com/forum/excel...-separated-list-pull-cell-value-same-row.html

Below I have 2 tables, I'm looking to match the table 1 "ID" that is comma delimited with the single "ID" that is in Table 2. So that I could get all the "KEY'S" that are in Table 1 that match with these ID's to look like the "RESULT" Column that I manually created in table 2.

Table 1
IDKEY
240642,12345,82871

<tbody>
</tbody>
RT12347789

<tbody>
</tbody>
24312,12345,82872

<tbody>
</tbody>
RT12347790

<tbody>
</tbody>
24568,12345,82873

<tbody>
</tbody>
RT12347789

<tbody>
</tbody>
24568,12345,82873

<tbody>
</tbody>
RT12347792

<tbody>
</tbody>

<tbody>
</tbody>

Table 2
IDRESULT
12345RT12347789,RT12347790,RT12347792
240642RT12347789
24568RT12347789, RT12347792
24312RT12347790

<tbody>
</tbody>


Thanks ahead of time with any help you guys can provide.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
is that what you want?

with PowerQuery (aka Get&Transform)
Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"KEY", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"ID", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "ID"),
    #"Grouped Rows" = Table.Group(#"Split Column by Delimiter", {"ID"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Result", each Table.Column([Count],"KEY")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Result", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Sorted Rows" = Table.Sort(#"Extracted Values",{{"ID", Order.Ascending}})
in
    #"Sorted Rows"[/SIZE]

IDKEYIDResult
240642,12345,82871RT1234778912345RT12347789,RT12347790,RT12347789,RT12347792
24312,12345,82872RT12347790240642RT12347789
24568,12345,82873RT1234778924312RT12347790
24568,12345,82873RT1234779224568RT12347789,RT12347792
82871RT12347789
82872RT12347790
82873RT12347789,RT12347792
 
Upvote 0
Unfortunately I'm on 2013 at work and waiting to get approved for powerquery addin. Hopefully it will be soon as it sounds like it would be useful to have. I was wondering if there is any other way we can do this with a mix of a index match formula and a text join or maybe a Macro.
 
Upvote 0
PQ is very useful.
TEXTJOIN() is from 365 so it doesn't exist in 2013.

Maybe someone else will give you formula or VBA solution

Good luck and have a nice day
 
Upvote 0
How about
Code:
Function MyLookup(St As String, Rng As Range) As String
   Dim cl As Range
   For Each cl In Rng
      If InStr(1, cl, St) > 0 Then
         If MyLookup = "" Then MyLookup = cl.Offset(, 1) Else MyLookup = MyLookup & ", " & cl.Offset(, 1)
      End If
   Next cl
End Function


Excel 2013/2016
ABCGHIJ
1IDKEYID
2240642, 12345, 82871RT1234778912345RT12347789, RT12347790, RT12347789, RT12347792
324312,12345, 82872RT12347790240642RT12347789
424568, 12345, 82873RT1234778924568RT12347789, RT12347792
524568, 12345, 82873RT1234779224312RT12347790
vor
Cell Formulas
RangeFormula
J2=MyLookup(I2,A$2:A$5)
 
Upvote 0
Hi Fluff, I think this is working, I do get some "#VALUE!" errors not sure why yet. The way I'm doing this is by comparing 2 worksheets "=MYLOOKUP(A2,RESULTS!$A$2:$A$14075)". Also is there a way to have the result in the J column only show the unique ID's and non duplicates. Like in column 2J could it be just "RT12347789", "RT12347790", "RT12347792"
 
Upvote 0
Try
Code:
Function MyLookup(St As String, Rng As Range) As String
   Dim Cl As Range
   With CreateObject("scripting.dictionary")
      For Each Cl In Rng
         If InStr(1, Cl, St) > 0 Then .Item(Cl.Offset(, 1).Value) = Empty
      Next Cl
      MyLookup = Join(.keys, ", ")
   End With
End Function
 
Upvote 0
I think the #VALUE errors is happening because of the duplicates as I only get the error for 2 ID's where the KEY has a dupe of over 2K records. Just seeing the new code. Will try that now. Thanks!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

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