Compare delimited strings to a list

Bequia

New Member
Joined
Jun 5, 2018
Messages
6
Hi I have a workbook with two columns A & B.


Each cell in Column A contains delimited strings:
Example A1 contains OT6, PA3, PU4, PR2, PL8
A2 contains: AP3, AP, AP4, AP10


I would like to compare these cells in column A to a list in column B and return the answer if any of the values in A1 or A2 exists. It's a big workbook so column A has about 50 rows with delimited strings.


I'm able to do the reverse, that is, look up the values in B that exists in A however I would like to know the values in A that do not exist in B.


Thanks in advance!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Are you looking for a formula, or is a macro acceptable?
 
Upvote 0
How about
Code:
Sub ChkExists()
   Dim ary As Variant
   Dim Cl As Range
   Dim i As Long, j As Long
   
   ary = Range("A1", Range("A" & Rows.Count).End(xlUp))
   With CreateObject("scripting.dictionary")
      For i = 1 To UBound(ary)
         For j = 0 To UBound(Split(ary(i, 1), ", "))
            If Not .exists(Split(ary(i, 1), ", ")(j)) Then .Add Split(ary(i, 1), ", ")(j), Nothing
         Next j
      Next i
      For Each Cl In Range("B1", Range("B" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then .Remove Cl.Value
      Next Cl
      Range("C1").Resize(.Count).Value = Application.Transpose(.keys)
   End With
End Sub
 
Upvote 0
I initially got a run time error here "Range("C1").Resize(.Count).Value = Application.Transpose(.keys)" however I added a column heading to both columns in the workbook and didn't receive a run-time error.

When I run the macro it only returns contents from the first cell and doesn't cycle through the list. I tested this by renaming the column headers. Do you know of a way for me to upload the workbook? That may be quicker.

Thanks!
 
Upvote 0
You cannot upload files to this site, but you can upload to a files share site such as OneDrive, DropBox, GoogleDrive. Mark for sharing & post the link to the thread
 
Upvote 0
In your op you said
I would like to know the values in A that do not exist in B.
now you are saying
What I would like to do is find the data/strings in Column A that exist in Column B.
Which is it?
 
Upvote 0
In that case the code I supplied in post#4 works on your test file.
Although as you ave added a header row, you'll need to change A1 & B1 to A2 & B2
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,174
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