hi I'm new to vba and I'm trying to write a code that will delete duplicate rows if say values in column C match up. But I want to delete the row that has the earliest time stamp heres an example.
<tbody>
</tbody>
Since in column C row 2 and 4 have the same value i want VBA to delete row 2 since the time stamp is earlier than row 4. heres what the output would look like
<tbody>
</tbody>
heres what i have so far:
This code is deleting the first duplicate but i want it to delete the row that has the earliest time stamp. Thanks for the help
<tbody>
</tbody>
Number | time stamp | round | device |
5 | 16/6/22:39:44 | 5 | 15 |
4 | 16/6/22:39:44 | 2 | 16 |
8 | 16/5/22:39:44 | 8 | 17 |
6 | 16/5/2:40:12 | 2 | 18 |
<tbody>
</tbody>
Since in column C row 2 and 4 have the same value i want VBA to delete row 2 since the time stamp is earlier than row 4. heres what the output would look like
Number | time stamp | round | device |
5 | 16/6/22:39:44 | 5 | 15 |
8 | 16/6/22:39:44 | 8 | 17 |
6 | 16/5/2:40:12 | 2 | 18 |
<tbody>
</tbody>
heres what i have so far:
HTML:
Sub Dup()
Dim rCell As Range
Dim Lastrow As Long
Dim rngDel As Range
Lastrow = Range("C" & Rows.Count).End(xlUp).Row
For Each rCell In Range("C1:C" & Lastrow)
If Application.CountIf(Range(rCell, Range("C" & Lastrow)), rCell) > 1 Then
If rngDel Is Nothing Then
Set rngDel = rCell.EntireRow
Else
Set rngDel = Union(rngDel, rCell.EntireRow)
End If
End If
Next rCell
If Not rngDel Is Nothing Then rngDel.DeleteEnd Sub
This code is deleting the first duplicate but i want it to delete the row that has the earliest time stamp. Thanks for the help
<tbody> </tbody> |
<tbody>
</tbody>