Sub test()
Dim a, i As Long, ii As Long, txt As String
Dim n As Long, e, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
With Cells(1).CurrentRegion
' store data in an array to speed up the process
a = .Value
.ClearContents
For i = 1 To UBound(a, 1)
' unique key (name/Col. D & Address(Col. L, M & N)
' joined by Chr(2) which is merely used in the real world for the safety.
txt = Join(Array(a(i, 4), a(i, 12), a(i, 13), a(i, 14)), Chr(2))
If Not dic.exists(txt) Then
' if unique, increase the counter "n", add txt to the dictionary with empty value
n = n + 1: dic(txt) = Empty
' substitute the row value to "n"th row in array "a"
For ii = 1 To UBound(a, 2)
a(n, ii) = a(i, ii)
Next
Else
' If not unique, change its item to the array of that row.
' this is for the deleted row for the dups.
dic(txt) = Application.Index(a, i, 0)
End If
Next
' loop through the dictionary
For Each e In dic.keys
' If item is not an array then remove it from the dictionary
' so that, if some remains, it will be dups to be reported.
If Not IsArray(dic(e)) Then dic.Remove e
Next
' dump the data from the array
.Resize(n).Value = a
With Sheets.Add.Cells(1).Resize(, .Columns.Count + 1)
' if any item remains in dictionary
If dic.Count Then
' dump the items to the range
.Resize(dic.Count).Value = Application.Index(dic.items, 0, 0)
End If
End With
End With
End Sub
Bookmarks