Comparing data in 2 columns

dougebowl

Board Regular
Joined
Feb 22, 2010
Messages
60
I am currently using the Macro below to compare data in 2 columns. I am looking to determine if the values in the 2 columns "Match" or do not ("No Match"). This Macro does not care the order of the values, just if they Match or don't Match.

I am looking for help to modify this Macro to ignore duplicate values in a particular cell.

Example:

Column A Column B
A;B;C C;B;A;C I need this to show as Match as I am not concerned if duplicate values are present. Just that the values are the same in both columns.

Thanks in advance for the help!

Dim Rng As Range, Dn As Range, Sp As Variant, S As Variant
Dim Txt1 As String, Txt2 As String
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
For Each Dn In Rng
Txt1 = Replace(Dn.Value, " ", "")
Txt2 = Replace(Dn.Offset(, 1).Value, " ", "")
Sp = Split(Txt1, ";")
For Each S In Sp
If InStr(Txt2, Trim(S)) = 0 Or Len(Txt1) <> Len(Txt2) Then
Dn.Offset(, 2) = "No Match"
Exit For
Else
Dn.Offset(, 2) = "Match"
End If
Next S
Next Dn
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Does this do what you want...

Code:
Sub test()


    Dim Rng As Range, Dn As Range, Sp As Variant, S As Variant
    Dim Txt1 As String, Txt2 As String
    Dim i As Long


    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        Txt1 = Replace(Dn.Value, " ", "")
        Txt2 = Replace(Dn.Offset(, 1).Value, " ", "")
        Sp = Split(Txt1, ";")
            For i = LBound(Sp) To UBound(Sp)
                If Not InStr(Txt2, Trim(Sp(i))) > 0 Then
                    Dn.Offset(, 2) = "No Match"
                    Exit For
                End If
                Dn.Offset(, 2) = "Match"
            Next
    Next Dn
    
End Sub
 
Upvote 0
I am glad it works, I was happy to help. Thanks for the feedback!
 
Upvote 0

Forum statistics

Threads
1,224,862
Messages
6,181,465
Members
453,045
Latest member
Abraxas_X

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