Macro-creating new unique record

Ruthanne

Board Regular
Joined
Mar 2, 2004
Messages
123
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.
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
change
Code:
Sheets("Master").Range("a" & Rows.Count).End(xlUp)(2)
to
Code:
Sheets("Master").Range("a1")
 
Upvote 0

Forum statistics

Threads
1,215,324
Messages
6,124,250
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top