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.
[TABLE="width: 500"]
<tbody>[TR]
[TD]Number[/TD]
[TD]time stamp[/TD]
[TD]round[/TD]
[TD]device[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]16/6/22:39:44[/TD]
[TD]5[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]16/6/22:39:44[/TD]
[TD]2[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]16/5/22:39:44[/TD]
[TD]8[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]16/5/2:40:12[/TD]
[TD]2[/TD]
[TD]18[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="width: 500"]
<tbody>[TR]
[TD]Number[/TD]
[TD]time stamp[/TD]
[TD]round[/TD]
[TD]device[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]16/6/22:39:44[/TD]
[TD]5[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]16/6/22:39:44[/TD]
[TD]8[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]16/5/2:40:12[/TD]
[TD]2[/TD]
[TD]18[/TD]
[/TR]
</tbody>[/TABLE]
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[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 500"]
<tbody>[TR]
[TD]Number[/TD]
[TD]time stamp[/TD]
[TD]round[/TD]
[TD]device[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]16/6/22:39:44[/TD]
[TD]5[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]16/6/22:39:44[/TD]
[TD]2[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]16/5/22:39:44[/TD]
[TD]8[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]16/5/2:40:12[/TD]
[TD]2[/TD]
[TD]18[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="width: 500"]
<tbody>[TR]
[TD]Number[/TD]
[TD]time stamp[/TD]
[TD]round[/TD]
[TD]device[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]16/6/22:39:44[/TD]
[TD]5[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]16/6/22:39:44[/TD]
[TD]8[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]16/5/2:40:12[/TD]
[TD]2[/TD]
[TD]18[/TD]
[/TR]
</tbody>[/TABLE]
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[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]