Hello, I’ve been working with this macro to compare two worksheets and copy the matches to a third sheet. Not knowing vb very well can someone show me how to modify this to only copy what is not found?
Sheet1 and Sheet2 column A is the unique id.
If no match is found between Sheet1 and Sheet2 then copy the row in Sheet1 to Sheet3
This works below to copy the matches but I’m looking for what is not found now.
Sub test()
Dim rng As Range, c As Range, cfind As Range
On Error Resume Next
Worksheets("sheet3").Cells.Clear
With Worksheets("sheet1")
Set rng = Range(.Range("A2"), .Range("a2").End(xlDown))
For Each c In rng
With Worksheets("sheet2")
Set cfind = .Columns("A:A").Cells.Find _
(what:=c.Value, lookat:=xlWhole)
If cfind Is Nothing Then GoTo line1
c.EntireRow.Copy Worksheets("sheet3").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End With 'sheet 2
line1:
Next c
Application.CutCopyMode = False
End With 'sheet 1
End Sub
Related:
Vba code to compare two excel sheets and highlight differences
Vba code to compare two excel sheets and copy differences - Best answers