Select the column that contains duplicate entries and run the following macro.
- Public Sub DeleteDuplicateRows()
- Dim rowIndex,rowCount,columnIndex As Long
- Dim value As Variant
- Dim testRange As Range
- rowCount = ActiveSheet.UsedRange.Rows.count
- columnIndex = ActiveCell.Column 'Column that contains duplicates
- Set testRange = Range(cells(1,columnIndex), cells(rowCount, columnIndex))
- For rowIndex = rowCount To 2 Step -1 'Iterating from bottom to retain first occurrence
-
- value = testRange.Cells(rowIndex, 1).Value
-
- If Application.WorksheetFunction.CountIf(testRange.Columns(1), value) > 1 Then
- testRange.Rows(rowIndex).EntireRow.Delete 'deletes duplicate rows
- End If
-
- Next rowIndex
-
- End Sub