Deleting Rows based on the duplicate contents of a single cell

J

Jim Berglund

I have a data base of addresses for homes. The data is repeated in many
cases based on previous listings or sales, and I want to only save the
latest record, deleting the earlier ones.

I've sorted the data based on date, and would like to delete row( i ) if the
text in Cell(i,1) is the same as the text in Cell(i-1,1)

I've made a few attempts, but have had no joy.

This seems like a pretty trivial exercise - I only need what would be in the
if...end if portion.

Any suggstions would be appreciated

Thanks,
Jim
 
J

JLGWhiz

Deleting rows should work from the bottom up.

Sub delRw()
Dim lstRw As Long, Dim ws As Worksheet
Set ws = ActiveSheet
lstRw = ws.Cells(Rows.Count, 1).End(xlUp).Row
For i = lstRw To 2 Step -1
If ws.Cells(i, 1).Value = ws.Cells(i-1, 1).Value Then
ws.Cells(i, 1).EntireRow.Delete
End If
Next
End Sub
 
Top