Exceladd1ct
Board Regular
- Joined
- Feb 10, 2019
- Messages
- 76
Hello,
I want to remove all duplicates but keep the last one.
I found this code and adapted it to my situation. But I got stuck because the code only compares and removes the next value upwards in order to keep the last duplicate and delete the rest. But I have 3, 4, 5 or more duplicates.
Can anyone please help me get this done?
I want to remove all duplicates but keep the last one.
I found this code and adapted it to my situation. But I got stuck because the code only compares and removes the next value upwards in order to keep the last duplicate and delete the rest. But I have 3, 4, 5 or more duplicates.
Can anyone please help me get this done?
Code:
Sub Dupe_Killer_Keep_Last()
Dim lrow As Long
For lrow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Cells(lrow, 2) = Cells(lrow, 2).Offset(-1, 0) Then
Cells(lrow, 2).Offset(-1, 0).Value = ""
End If
Next lrow
End Sub