View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
merjet merjet is offline
external usenet poster
 
Posts: 812
Default Deleting Duplicate Rows but keeping the most recent.

Like Nicholson, I recommend the rows be sorted by work order number
first. Sorting them secondarily by date would be even better.

If they are sorted by work order number, then the following should
work.

Sub DeleteTheOldies()
Dim RowNdx As Long
For RowNdx = Range("b1").End(xlDown).Row To 2 Step -1
Do While Cells(RowNdx, "b").Value = Cells(RowNdx - 1, "b").Value
If Cells(RowNdx, "s").Value <= Cells(RowNdx - 1, "s").Value Then
Rows(RowNdx).Delete
Else
Rows(RowNdx - 1).Delete
End If
RowNdx = RowNdx - 1
If RowNdx = 1 Then Exit Sub
Loop
Next RowNdx
End Sub

HTH,
Merjet