Hey there,

I have VBA codes to delete rows that have duplicate values in column D, and only keep rows that have the highest number value under column J. The problem that I've ran into is that column K contains different dates for each duplicate and the dates (latest) that I need to keep end up being deleted along with the unwanted duplicate rows. Is there anyway to delete the duplicate rows but only keep the cell that has the latest date in column K? TIA.

Sub CleanItUp()
Dim LR As Long, Rw As Long, DelRNG As Range

'Delete duplicates and keep ones that have the highest "Activity Number"
LR = Range("A" & Rows.Count).End(xlUp).Row
Set DelRNG = Range("A" & LR + 10)   'generic cell to start the delete row list

Columns("A:J").Sort Key1:=Range("D1"), Order1:=xlDescending, Key2:=Range("J1"), _
    Order2:=xlDescending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
    For Rw = LR To 3 Step -1
        If Cells(Rw, "A") = Cells(Rw - 1, "A") Then _
            Set DelRNG = Union(DelRNG, Cells(Rw, "A"))
    Next Rw
DelRNG.EntireRow.Delete xlShiftUp
Set DelRNG = Nothing
End Sub