PDA

View Full Version : Delete duplicates



Djblois
06-13-2006, 11:40 AM
I want to create a macro that would find a word in a column and then every other instance of that code it would delete the whole row.

Ex:
If I am looking for test in Column A, it finds it in (1, 1) and then finds it in the next 5 rows. It will leave the one in (1, 1) alone and delete all the rows that have test in it.(only if it is in the same column.

mdmackillop
06-13-2006, 11:45 AM
Check "Find Method" in the help file, the code example there should be readily adapted to this task.
Regards
MD

lucas
06-13-2006, 12:40 PM
or try this:
Sub RemoveDuplicates()
Worksheets("Sheet1").Range("A1").Sort _
key1:=Worksheets("Sheet1").Range("A1")
Set currentCell = Worksheets("Sheet1").Range("A1")
Do While Not IsEmpty(currentCell)
Set nextCell = currentCell.Offset(1, 0)
If nextCell.Value = currentCell.Value Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Loop
End Sub