View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JW[_2_] JW[_2_] is offline
external usenet poster
 
Posts: 638
Default preserve last row while looking through a column of duplicate information

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

Marcusdmc wrote:
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