Excel VBA comma separated data comparison

bobbyexcel

Board Regular
Joined
Nov 21, 2019
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Can someone help me on my below requirement please. My data looks like this and I want to check the rows matching or not but they are comma separated..
I've A,B columns and want to get the result(Match or not) in column C.

Book2
ABC
1Data 1Data 2Result
2abc, bccbcc, abcMatch
3xyz, mnoabc, xyzUnMatch
4mno, tuvmno, tuvMatch
5abb, bbcabb, bbcMatch
Sheet1
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Maybe it will help you with formula:

varios 23jun2022 rango con indice.xlsm
ABC
1Data 1Data 2Result
2abc, bccbcc, abcMatch
3xyz, mnoabc, xyzUnMatch
4mno, tuvmno, tuvMatch
5abb, bbcabb, bbcMatch
Hoja1
Cell Formulas
RangeFormula
C2:C5C2=IF(SUM(--ISNUMBER(SEARCH(TRIM(MID(SUBSTITUTE(B2, ",", REPT(" ",255)),255*(ROW($1:$2)-1)+1,255)),A2)))=2,"Match", "UnMatch")
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
It is not working if you have cell value like ab,cbcc.. It says matched but not..
 
Upvote 0
Try:

Dante Amor
ABC
1Data 1Data 2Result
2abc, bccbcc, abcMatch
3xyz, mnoabc, xyzUnMatch
4mno, tuvmno, tuvMatch
5abb, bbcabb, bbcMatch
6ab, cbccab, bbccUnMatch
7ab, cbccab, cbccMatch
Hoja1
Cell Formulas
RangeFormula
C2:C7C2=IF(SUM(--ISNUMBER(SEARCH(","&TRIM(MID(SUBSTITUTE(B2, ",", REPT(" ",255)),255*(ROW($1:$2)-1)+1,255))&",",","&TRIM(SUBSTITUTE(A2,", ",","))&",")))=2,"Match", "UnMatch")
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Solution
It is not working if you have cell value like ab,cbcc.. It says matched but not..
All you examples showed two 3 character substrings separated by a comma so obviously your example was not truly representative. Any other surprises for us, like more than two substrings per cell?
 
Upvote 0
Try:

Dante Amor
ABC
1Data 1Data 2Result
2abc, bccbcc, abcMatch
3xyz, mnoabc, xyzUnMatch
4mno, tuvmno, tuvMatch
5abb, bbcabb, bbcMatch
6ab, cbccab, bbccUnMatch
7ab, cbccab, cbccMatch
Hoja1
Cell Formulas
RangeFormula
C2:C7C2=IF(SUM(--ISNUMBER(SEARCH(","&TRIM(MID(SUBSTITUTE(B2, ",", REPT(" ",255)),255*(ROW($1:$2)-1)+1,255))&",",","&TRIM(SUBSTITUTE(A2,", ",","))&",")))=2,"Match", "UnMatch")
Press CTRL+SHIFT+ENTER to enter array formulas.
This working as expected but how do I incorporate into VBA code. It says expected end of statement.

VBA Code:
Dim lastrownew2 As Integer
    lastrownew2 = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
   
    For Each c In Range("D2:D" & lastrownew2
        c.value = "{=IF(SUM(--ISNUMBER(SEARCH(","&TRIM(MID(SUBSTITUTE(F &c.row, ",", REPT(" ",255)),255*(ROW($1:$2)-1)+1,255))&",",","&TRIM(SUBSTITUTE(G&c.row,", ",","))&",")))=2,"Match", "UnMatch")}"
        c.Formula = c.Value
    Next
 
Last edited:
Upvote 0
All you examples showed two 3 character substrings separated by a comma so obviously your example was not truly representative. Any other surprises for us, like more than two substrings per cell?
All my actual data has only 1 character but I just gave one example with 3 chars separated with comma.

Eg.. this is how my data looks
Book3
BC
3s,22,s
43,s3,s
54,ss,s
6s,s4,s
Sheet1
 
Upvote 0
but I just gave one example with 3 chars separated with comma.
Actually, your original samples were separated by comma and space.
Assuming comma only, here are two more to test, depending on whether or not you have the TEXTSPLIT function, column C, otherwise column D

22 06 24.xlsm
ABCD
1Data 1Data 2Result 1Result 2
2abc,bccbcc,abcMatchMatch
3xyz,mnoabc,xyzUnmatchUnmatch
4mno,tuvmno,tuvMatchMatch
5abb,bbcabb,bbcMatchMatch
6s,22,sMatchMatch
73,s3,sMatchMatch
84,ss,sUnmatchUnmatch
9s,s4,sUnmatchUnmatch
Compare columns
Cell Formulas
RangeFormula
C2:C9C2=IF(PRODUCT(--(SORT(TEXTSPLIT(A2,","),,,1)=SORT(TEXTSPLIT(B2,","),,,1))),"Match","Unmatch")
D2:D9D2=IF(PRODUCT(--(SORT(FILTERXML("<p><c>"&SUBSTITUTE(A2,",","</c><c>")&"</c></p>","//c"))=SORT(FILTERXML("<p><c>"&SUBSTITUTE(B2,",","</c><c>")&"</c></p>","//c")))),"Match","Unmatch")
 
Upvote 0
yes @Peter_SSs for the formula you mentioned in Col D, I want to include the same in vba code. could you please help me on that.

VBA Code:
    Dim lastrownew2 As Integer
    lastrownew2 = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
   
    For Each c In Range("D2:D" & lastrownew2)
        c.Value = "=IF(PRODUCT(--(SORT(FILTERXML("<p><c>"&SUBSTITUTE(A2,",","</c><c>")&"</c></p>","//c"))=SORT(FILTERXML("<p><c>"&SUBSTITUTE(B2,",","</c><c>")&"</c></p>","//c")))),"Match","Unmatch")"

        c.Formula = c.Value
    Next
 
Upvote 0
This working as expected but how do I incorporate into VBA code. It says expected end of statement.

VBA Code:
Sub WithFormula()
  Dim lr As Long
  lr = Range("B" & Rows.Count).End(3).Row
  With Range("C2")
    .FormulaArray = "=IF(SUM(--ISNUMBER(SEARCH("",""&TRIM(MID(SUBSTITUTE(B2, "","", REPT("" "",255))" & _
        ",255*(ROW($1:$2)-1)+1,255))&"","","",""&TRIM(SUBSTITUTE(A2,"", "","",""))&"","")))=2,""Match"", ""UnMatch"")"
    If lr > 2 Then .Copy Range("C3:C" & lr)
    .Resize(lr - 1).Value = .Resize(lr - 1).Value
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,246
Members
449,093
Latest member
Vincent Khandagale

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