Cell with comma seperated values and vlookup

chrisnilu

New Member
Joined
Aug 8, 2017
Messages
8
1st table/report has cells with single values as well as multiple values separated by comma.

[TABLE="class: outer_border, width: 60"]
<tbody>[TR]
[TD]Identifier
[/TD]
[/TR]
[TR]
[TD]AA
[/TD]
[/TR]
[TR]
[TD]XY,AA,YX
[/TD]
[/TR]
[TR]
[TD]BE
[/TD]
[/TR]
[TR]
[TD]RE,WX,EW,XT
[/TD]
[/TR]
[TR]
[TD]AB,ER,
[/TD]
[/TR]
</tbody>[/TABLE]


if any of the values in the cell is there in the 2nd table I need to filter the 1st report.

2nd table/report
[TABLE="class: outer_border, width: 54"]
<tbody>[TR]
[TD]Identifier
[/TD]
[/TR]
[TR]
[TD]WR
[/TD]
[/TR]
[TR]
[TD]AA
[/TD]
[/TR]
[TR]
[TD]XY
[/TD]
[/TR]
[TR]
[TD]BE
[/TD]
[/TR]
</tbody>[/TABLE]

As BE & AA are available in the 2nd table, 1st report should be filtered and should show only the 1st 3 rows (table values with BE & AA )

If the 1st report/table only has single values in a cell I can do a vlookup but as this has comma separated values how should I approach this ?

seeking for immediate assistance as I would need this for my work tomorrow. THANKS
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Use the autofilter.
Unselect all
Filter for each item on the second table by typing them in one at a time
The first time any rows are returned accept that filter.
The second and subsequent times rows are returned, choose the option "Add current selection to filter each time"
The lines from table 1 that contain any of the items entered will be displayed.
 
Last edited:
Upvote 0
If the 1st report/table only has single values in a cell I can do a vlookup but as this has comma separated values how should I approach this ?

Hi, another option you could try:


Excel 2013/2016
ABCD
1IdentifierFilter ?Table 2
2AATRUEWR
3XY,AA,YXTRUEAA
4BETRUEXY
5RE,WX,EW,XTFALSEBE
6AB,ER,FALSE
Sheet1
Cell Formulas
RangeFormula
B2=ISNUMBER(LOOKUP(1,-SEARCH(","&$D$2:$D$5&",",","&A2&",")))
 
Upvote 0
Unfortunately both the tables has thousands of records :(
What is the maximum number of rows for Table 1 (don't really need to know the number for the second table for the method I am thinking about)?

Are your tables real Excel Table objects or just groups of cells that you think of as tables?

Where are the tables located at?
 
Upvote 0
Maybe Advanced Filter + a formula

Something like

[Table="class: grid"][tr][td="bgcolor: #DCE6F1"][/td][td="bgcolor: #DCE6F1"]
A
[/td][td="bgcolor: #DCE6F1"]
B
[/td][td="bgcolor: #DCE6F1"]
C
[/td][td="bgcolor: #DCE6F1"]
D
[/td][td="bgcolor: #DCE6F1"]
E
[/td][/tr]
[tr][td="bgcolor: #DCE6F1"]
1
[/td][td]
Identifier​
[/td][td][/td][td]
Identifier​
[/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
2
[/td][td]
AA​
[/td][td][/td][td]
WR​
[/td][td][/td][td]
TRUE​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
3
[/td][td]
XY,AA,YX​
[/td][td][/td][td]
AA​
[/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
4
[/td][td]
BE​
[/td][td][/td][td]
XY​
[/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
5
[/td][td]
RE,WX,EW,XT​
[/td][td][/td][td]
BE​
[/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
6
[/td][td]
AB,ER,​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
7
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]


Leave E1 blank

Formula in E2
=SUMPRODUCT(--ISNUMBER(SEARCH(C$2:C$5,A2)))>0

Select A1:A6 and apply Advanced Filter with Criteria Range=$E$1:$E$2

Hope this helps

M.
 
Upvote 0
Maybe Advanced Filter + a formula
Hi Marcelo
I also considered Adv Filter but the OP says thousands of rows in both tables and, for me at least, that made Adv Filter painfully slow.

Also, just noting with your formula that the OP would need to confirm that all individual Identifiers are exactly 2 characters long. Otherwise a formula like FormR's would be required.
 
Upvote 0
Hi Peter,

You are right, with thousands of rows in both tables adv filter should not be used - bad performance.
Maybe a macro using variant arrays...

M.
 
Upvote 0
Maybe a macro using variant arrays...
I have no idea how fast this will be given the number of rows involved, but possibly this macro (the layout info is set in the four highlighted Const statements)...
Code:
[table="width: 500"]
[tr]
	[td]Sub FilterIndentifiers()
  Dim R As Long, UnusedCol As Long, Table2 As Variant
  
[B][COLOR="#FF0000"]  Const Table1SheetName = "Sheet1"
  Const Table2SheetName = "Sheet2"
  Const Table1Col = "A"
  Const Table2Col = "A"
[/COLOR][/B]  
  With Sheets(Table2SheetName)
    Table2 = .Range(.Cells(2, Table2Col), .Cells(Rows.Count, Table2Col).End(xlUp))
  End With
  Application.ScreenUpdating = False
  With Sheets(Table1SheetName)
    UnusedCol = .Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column + 1
    .AutoFilterMode = False
    .Rows.Hidden = False
    With .Range(.Cells(1, Table1Col), .Cells(Rows.Count, Table1Col).End(xlUp))
      For R = 1 To UBound(Table2)
        .AutoFilter 1, "*" & Table2(R, 1) & "*"
        Intersect(.SpecialCells(xlVisible).EntireRow, .Columns(UnusedCol)).Value = "X"
      Next
      .Parent.AutoFilterMode = False
      .Columns(UnusedCol).SpecialCells(xlBlanks).EntireRow.Hidden = True
      .Columns(UnusedCol).Clear
    End With
  End With
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
this looks simple but in my case I have to do the filtering in Column A if the same value is there in Column C ( cannot do it the other way due to the nature of data ) . Column A cells might have single or multiple values and Column C will always have single values.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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