Excel - Compare data between different columns

October 2016


I need a macro to compare data between different columns

a(reference data) b(raw data) c(status) 

ab xc 
bc cb 
cd ab match 
ef pq 
gh cd match 
ij zx 
kl qr 
bc match 
kl match 


Try this:

Try the following code:
Sub test()
Dim lRow, lRow2 As Integer
lRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
lRow2 = Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Row

For Each cell In Sheets("Sheet1").Range("A1:A" & lRow)
    With Sheets("Sheet2").Range("D1:D" & lRow2)
        Set c = .Find(cell, LookIn:=xlValues)
        If Not c Is Nothing Then
        firstAddress = c.Address
                Sheets("Sheet3").Cells(c.Row, "A") = "Match"
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
Next cell

End Sub

Thanks to TrowaD for this tip.

Related :

This document entitled « Excel - Compare data between different columns » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.