Macro to compare 2 sheets and copy differences

Solved/Closed
ehusar Posts 1 Registration date Monday 3 February 2020 Status Member Last seen 3 February 2020 - 3 Feb 2020 à 12:59
AirMaple Posts 1 Registration date Saturday 15 February 2020 Status Member Last seen 17 February 2020 - 15 Feb 2020 à 01:44
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:

2 responses

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
4 Feb 2020 à 11:29
Hi Ehusar,

For that you only have to add NOT to code line 12:
If not cfind Is Nothing Then GoTo line1 


Best regards,
Trowa