Hi SilverFox,
See how this goes:
Option Explicit
Sub Macro1()
'Written by Trebor76
'Visit my website www.excelguru.net.au
Dim objMyUniqueEntries As Object
Dim lngRowStart As Long, _
lngRowEnd As Long, _
lngMyRow As Long, _
lngMyCounter As Long
Dim rngDelRange As Range
Set objMyUniqueEntries = CreateObject("Scripting.Dictionary")
lngRowStart = 2 'Starting row number for the data. Change to suit.
lngRowEnd = Range("A:X").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Application.ScreenUpdating = False
For lngMyRow = lngRowStart To lngRowEnd
If objMyUniqueEntries.exists(CStr(Range("A" & lngMyRow) & Range("B" & lngMyRow) & Range("G" & lngMyRow))) = False Then
lngMyCounter = lngMyCounter + 1
objMyUniqueEntries.Add CStr(Range("A" & lngMyRow) & Range("B" & lngMyRow) & Range("G" & lngMyRow)), lngMyCounter
Else
If rngDelRange Is Nothing Then
Set rngDelRange = Cells(lngMyRow, "A")
Else
Set rngDelRange = Union(rngDelRange, Cells(lngMyRow, "A"))
End If
End If
Next lngMyRow
Set objMyUniqueEntries = Nothing
'If the 'rngDelRange' range has been set, then...
If Not rngDelRange Is Nothing Then
'...delete the row(s) from it.
rngDelRange.EntireRow.Delete
Application.ScreenUpdating = True
MsgBox "The duplicate rows have now been deleted.", vbInformation, "Delete Duplicate Row Editor"
Set rngDelRange = Nothing
'Else...
Else
'...display a message that no rows were deleted as they were all unique.
Application.ScreenUpdating = True
MsgBox "There were no rows deleted as no duplicates were found.", vbExclamation, "Delete Duplicate Row Editor"
End If
End Sub
Regards,
Robert
Bookmarks