I would like this code to only create a new row if there is not a match between columns D & E of two worksheets. Right now it is creating a new record (pasting columns A-N into first blank row of WS "Master") even when there is a match (& already a record).
Thank you in advance for your help.
Thank you in advance for your help.
Code:
Sub newRecord()
Dim a, i As Long, ii As Integer, z As String
a = Sheets("WeeklyJob").Range("a1").CurrentRegion.Resize(, 14).Value
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
z = a(i, 4) & ";" & a(i, 5)
If Not .exists(z) Then
.Add z, Array(a(i, 1), a(i, 2), a(i, 3), a(i, 4), a(i, 5), a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10), a(i, 11), a(i, 12), a(i, 13), a(i, 14))
End If
Next
a = Sheets("Master").Range("a1").CurrentRegion.Resize(, 14).Value
For i = 1 To UBound(a, 1)
z = a(i, 4) & ";" & a(i, 5)
If .exists(z) Then
w = .Item(z)
For ii = 6 To 14: a(i, ii) = w(ii - 1): Next
.Remove z
End If
Next
If .Count > 0 Then
Sheets("Master").Range("a" & Rows.Count).End(xlUp)(2) _
.Resize(.Count, 14).Value = Application.Transpose(Application.Transpose(.items))
End If
End With