preserve last row while looking through a column of duplicate information

M

Marcusdmc

Is there a way to instead of deleting the extra rows after the first
duplicate is found, to delete all but the last one of the duplicates?
As in, keep the last duplicate, discard the ones above it. I know the
reverse can be done... Thanks for any direction!

-Marcus
 
J

JW

One way:
This will cycle through all cells in column A, starting at the bottom,
and delete the entire row above it if it is a match.
Sub delDups()
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
Do Until Cells(i, 1).Offset(-1, 0).Text <> Cells(i, 1).Text
Cells(i, 1).Offset(-1, 0).EntireRow.Delete
Loop
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top