Hi
try thid.
Code:
Option Explicit
Sub kTest()
Dim ka, k(), i As Long, n As Long, c As Long, d As Object
Dim DupeCount As Long, addr As String, wksNewData As Worksheet
Dim UniqueString As String
Const MasterSheet As String = "Sheet1" '<< adjust
Set d = CreateObject("scripting.dictionary")
d.comparemode = 1
ka = ThisWorkbook.Worksheets(MasterSheet).Range("a1").CurrentRegion.Resize(, 10).Value2
'loop thru master sheet
For i = 2 To UBound(ka, 1)
UniqueString = Trim(ka(i, 4)) & Trim(ka(i, 5)) '<<< adjust the columns
If Len(UniqueString) Then
d.Item(UniqueString) = Empty
End If
Next
Erase ka
Set wksNewData = ThisWorkbook.Worksheets(2)
ka = wksNewData.Range("a1").CurrentRegion.Resize(, 10).Value2
ReDim k(1 To UBound(ka, 1), 1 To UBound(ka, 2))
For i = 2 To UBound(ka, 1)
UniqueString = Trim(ka(i, 4)) & Trim(ka(i, 5)) '<<< adjust the columns
If Not d.exists(UniqueString) Then
n = n + 1
For c = 1 To UBound(ka, 2)
k(n, c) = ka(i, c)
Next
Else
DupeCount = DupeCount + 1
addr = addr & ",D" & i
If Len(addr) > 245 Then
wksNewData.Range(Mid(addr, 2)).Interior.Color = 65535
addr = vbNullString
End If
End If
Next
If Len(addr) > 1 Then
wksNewData.Range(Mid(addr, 2)).Interior.Color = 65535
addr = vbNullString
End If
If n Then
'append new record into the master sheet
With ThisWorkbook.Worksheets(MasterSheet)
.Range("a" & .Rows.Count).End(xlUp).Offset(1).Resize(n, UBound(k, 2)) = k
End With
End If
If DupeCount Then
MsgBox "There are " & DupeCount & " duplicates.", vbInformation
End If
End Sub
Bookmarks