0
Thanks

A few words of thanks would be greatly appreciated.

Excel - Compare data between different columns



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 
hj 
rh 
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
            Do
                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.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Excel - Compare data between different columns », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

0 Comments