I'm trying to do this code for a while now but with no success so far. I would like to copy rows from a sheet X to the end of another sheet Y if rows doesn't already exists in the sheet Y, based on a comparison of the data in columns A and C.
I already did the code when I just needed to compare with one column, and it worked perfectly. I put it just right there so you can see :
sourceLastRow = ws_src.Cells(ws_src.Rows.Count, "A").End(xlUp).Offset(1).Row
destLastRow = ws_dest.Cells(ws_dest.Rows.Count, "A").End(xlUp).Offset(1).Row
For Each rng In ws_src.Range("A2:A" & sourceLastRow)
Set foundVal = ws_dest.Range("A2:A" & destLastRow).Find(rng, LookIn:=xlValues, lookat:=xlWhole)
If foundVal Is Nothing Then
rng.EntireRow.Copy
ws_dest.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End If
Next rng
Unfortunately, when I tried to compare two columns I don't get the results I need. I tried the code below but it copy the first row of my first sheet without stopping :
Dim ws_src As Worksheet
Dim ws_dest As Worksheet
Dim rw_src As Range
Dim rw_dest As Range
Set ws_src = Worksheets(1)
Set ws_dest = Worksheets(2)
For Each rw_src In ws_src.Rows
For Each rw_dest In ws_dest.Rows
If ws_src.Cells(rw_src.row, 1).Value = ws_dest.Cells(rw_dest.row, 1).Value And ws_src.Cells(rw_src.row, 3).Value = ws_dest.Cells(rw_dest.row, 3).Value Then
Else: rw_src.EntireRow.Copy
ws_dest.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End If
Next rw_dest
Next rw_src
Thank you for your time !
Léa