View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
George Nicholson[_2_] George Nicholson[_2_] is offline
external usenet poster
 
Posts: 170
Default Deleting Duplicate Rows but keeping the most recent.

What is this code not doing for you? By all appearances it should do the
job *as long as the sheet is sorted in Workorder number*.

The only question in my mind is the line:
If Cells(RowNdx, "s").Value <= Cells(RowNdx - 1, "s").Value


In your case, if you have 2 records with the same Workorder AND same change
date, you will simply delete one of them, rather arbitrarily. You might want
to change <= to just < so if you have two workorders with the same change
date you leave them both intact for manual review/evaluation/deletion. Maybe
this is actually OK, it depends on your data and how ChangeDate gets
recorded.

--
George Nicholson

Remove 'Junk' from return address.


"Lynn A." wrote in message
om...
I am trying to delete duplicate rows in my spreadsheet. Please don't
just send a reference to Cip Pearson's website. I have been there,
found what I needed but I can't get it to work in my instance. Baby
steps and simplistic terms please.

The spreadsheet is a monthly upload that has 19 columns and has
between 500 - 4000. Currently column B is the workorder column this
is duplicated because over the month a workorder could be modified
several times, thus the duplicates.
Column S has the dates of the changes and that is where I would like
to find the most recent and then delete the other two, three sometimes
up to 10 records for each workorder.

Guidance on the use of the following code would be greatly
appreciated. I am new to "code" and would like to become better.



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

Thank you,

Lynn