Hello,
I have two sheets in which I am trying to append records from one to the other. The main list is ws2 and the second list, ws5, is the one to be populated with records from ws2 by appending record i to the last row in the list. Records are only to be appended where they do not exist in ws5. I am comparing on two different fields in both sheets to identify unique records. My issue is how to check if the record does not exist in ws5. Initially, ws5 will contain no records except for the column header, but will build up over time.
Here is my code so far. As I understand it, the For Each Cell statement will check through all existing records in ws5 comparing on the two different fields. I have learnt about loops used for checking through for matching records, however, I don't know how a loop could work to look for non-matching records. Somehow, the code needs to check through records in ws5 against those in ws2 and where the record does not exist in ws5, to append it.
Any help on this would be much appreciated.
I have two sheets in which I am trying to append records from one to the other. The main list is ws2 and the second list, ws5, is the one to be populated with records from ws2 by appending record i to the last row in the list. Records are only to be appended where they do not exist in ws5. I am comparing on two different fields in both sheets to identify unique records. My issue is how to check if the record does not exist in ws5. Initially, ws5 will contain no records except for the column header, but will build up over time.
Here is my code so far. As I understand it, the For Each Cell statement will check through all existing records in ws5 comparing on the two different fields. I have learnt about loops used for checking through for matching records, however, I don't know how a loop could work to look for non-matching records. Somehow, the code needs to check through records in ws5 against those in ws2 and where the record does not exist in ws5, to append it.
Any help on this would be much appreciated.
Code:
Public Sub bulk_update_finance_4()
Dim ws2 As Worksheet
Dim ws5 As Worksheet
Dim Cell As Range
Dim Finalrow3 As Long
Set ws2 = ThisWorkbook.Sheets("Interim")
Set ws5 = ThisWorkbook.Sheets("Erasmus Finance")
Finalrow2 = Sheets("Interim").Range("F" & Rows.Count).End(xlUp).Row
Finalrow3 = Sheets("Erasmus Finance").Range("F" & Rows.Count).End(xlUp).Row
On Error Resume Next
For i = 2 To Finalrow2
For Each Cell In ws5.Range("F7:F" & Finalrow3)
If Cell.Value <> ws2.Cells(i, 6).Value And _
Cell.Offset(, 3).Value <> ws2.Cells(i, 7).Value Then
ws2.Range("A:N" & i).Copy
ws5.Range(Finalrow3 + 1).PasteSpecial xlPasteValues
End If
Next Cell
Next i
End Sub