Comparing two cells with comma separated lists of values and returning any duplicates

CellHell

New Member
Joined
Apr 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Easy one to explain, but frustrating to try and resolve!... 1 cell has '7,8,9', the next cell has '8,9,10' and I want it to compare and report the overlap '8,9'. I can't split these out into separate cells due to the spreadsheet size as each cell might contain upto 12 or so values and ideally I would be able to simultaneously compare 8 or so cells together with the same operation (although even comparing 2 with multiple values would be very useful). It would be ok to CONCAT all the values into one cell and then pull out the duplicates perhaps? ...If it also reported the number of overlapped ; so '2' for '8,9' that would be great but suspect I could find a way for that easier bit. Any help would be really greatly appreciated , to my mind this should be simple and quite a common comparison but lost on this one!....if I have to scrub up on VBA to resolve then so be it. Thanks for reading!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This is a silly solution.

MrExcelPlayground2.xlsx
KL
15,6,7,8,9,108,9,10
28,9,10,11,12
Sheet4
Cell Formulas
RangeFormula
L1L1=TEXTJOIN(",",TRUE,XLOOKUP(VALUE(MID(K1,SORT(UNIQUE(IFERROR(FIND(",",K1,SEQUENCE(LEN(K1)))+1,1)),1,1),UNIQUE(IFERROR(FIND(",",K1,SEQUENCE(LEN(K1))),LEN(K1)+1))-(SORT(UNIQUE(IFERROR(FIND(",",K1,SEQUENCE(LEN(K1)))+1,1)),1,1)))),VALUE(MID(K2,SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1),UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2))),LEN(K2)+1))-(SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1)))),VALUE(MID(K2,SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1),UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2))),LEN(K2)+1))-(SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1)))),"",0))
 
Upvote 0
Hi & welcome to MrExcel.
A couple of options, the formula in C3 only works on a pc.
+Fluff 1.xlsm
ABC
1
27,8,9,1,14,157,9,14,15,19,2
39,10,15,117,9,14,15,19,2
47,23,19,26,2,3
514,19,2
6
Main
Cell Formulas
RangeFormula
C2C2=LET(a,TEXTJOIN(",",,A2:A5),b,TRIM(MID(SUBSTITUTE(a,",",REPT(" ",100)),SEQUENCE(LEN(a)-LEN(SUBSTITUTE(a,",",""))+1,,,100),100)),TEXTJOIN(",",,UNIQUE(FILTER(b,ISNA(MATCH(b, UNIQUE(b,,1),0))))))
C3C3=TEXTJOIN(",",,FILTERXML("<k><m>"&TEXTJOIN("</m><m>",,SUBSTITUTE(A2:A5,",","</m><m>"))&"</m></k>","//m[.=following-sibling::m]"))
 
Upvote 0
Solution
This is a silly solution.

MrExcelPlayground2.xlsx
KL
15,6,7,8,9,108,9,10
28,9,10,11,12
Sheet4
Cell Formulas
RangeFormula
L1L1=TEXTJOIN(",",TRUE,XLOOKUP(VALUE(MID(K1,SORT(UNIQUE(IFERROR(FIND(",",K1,SEQUENCE(LEN(K1)))+1,1)),1,1),UNIQUE(IFERROR(FIND(",",K1,SEQUENCE(LEN(K1))),LEN(K1)+1))-(SORT(UNIQUE(IFERROR(FIND(",",K1,SEQUENCE(LEN(K1)))+1,1)),1,1)))),VALUE(MID(K2,SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1),UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2))),LEN(K2)+1))-(SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1)))),VALUE(MID(K2,SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1),UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2))),LEN(K2)+1))-(SORT(UNIQUE(IFERROR(FIND(",",K2,SEQUENCE(LEN(K2)))+1,1)),1,1)))),"",0))
thanks so much James - if i knew you I would be buying you a pint at this stage. :)
 
Upvote 0
Hi & welcome to MrExcel.
A couple of options, the formula in C3 only works on a pc.
+Fluff 1.xlsm
ABC
1
27,8,9,1,14,157,9,14,15,19,2
39,10,15,117,9,14,15,19,2
47,23,19,26,2,3
514,19,2
6
Main
Cell Formulas
RangeFormula
C2C2=LET(a,TEXTJOIN(",",,A2:A5),b,TRIM(MID(SUBSTITUTE(a,",",REPT(" ",100)),SEQUENCE(LEN(a)-LEN(SUBSTITUTE(a,",",""))+1,,,100),100)),TEXTJOIN(",",,UNIQUE(FILTER(b,ISNA(MATCH(b, UNIQUE(b,,1),0))))))
C3C3=TEXTJOIN(",",,FILTERXML("<k><m>"&TEXTJOIN("</m><m>",,SUBSTITUTE(A2:A5,",","</m><m>"))&"</m></k>","//m[.=following-sibling::m]"))
thanks Fluff - again I would be buying you a pint if I knew you. I will test this version out tomorrow and let you know how I get on. thanks again, much appreciated.
 
Upvote 0
Hi Fluff, sorry one last one.... the XML formula is working great apart from one added complication - If I want non-adjacent cells instead of a range e.g. 'A2,B2,E2' instead of 'A2:E2' is this constrained by this type of formula (using XML) or is it just that I need to do something with SUBSTITUTE (I have only ever used this for singular references before and cant find an example with multiple non-adjacent cells, so not sure if I have to do something nested perhaps?). Apologies for my ignorance - I have read up on XML since getting this formula, but I can't fathom why it won't allow. Any further guidance, greatly appreciated.
 
Upvote 0
Hi Fluff, sorry one last one.... the XML formula is working great apart from one added complication - If I want non-adjacent cells instead of a range e.g. 'A2,B2,E2' instead of 'A2:E2' is this constrained by this type of formula (using XML) or is it just that I need to do something with SUBSTITUTE (I have only ever used this for singular references before and cant find an example with multiple non-adjacent cells, so not sure if I have to do something nested perhaps?). Apologies for my ignorance - I have read up on XML since getting this formula, but I can't fathom why it won't allow. Any further guidance, greatly appreciated.
ignore - sorry.... I should have known this one. I just needed to type it out and I figured out what I was doing wrong....sorry! and thanks.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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