Forum Discussion
minhhai91
Jun 25, 2021Copper Contributor
Duplicate management with condition
Hello,
I would like to delete the duplicates (red ones) and keep those with the oldest date (green) with a macro on VBA.
Thank you in advance,
Frédéric
Sort the range on column E, from oldest to newest.
Click Remove Duplicates on the Data tab of the ribbon.
Select only column A (ID), then click OK.
As a macro:
Sub RemoveDups() Application.ScreenUpdating = False With Range("A1").CurrentRegion .Sort Key1:=Range("E1"), Header:=xlYes .RemoveDuplicates Columns:=1, Header:=xlYes End With Application.ScreenUpdating = True End Sub
2 Replies
Sort the range on column E, from oldest to newest.
Click Remove Duplicates on the Data tab of the ribbon.
Select only column A (ID), then click OK.
As a macro:
Sub RemoveDups() Application.ScreenUpdating = False With Range("A1").CurrentRegion .Sort Key1:=Range("E1"), Header:=xlYes .RemoveDuplicates Columns:=1, Header:=xlYes End With Application.ScreenUpdating = True End Sub- minhhai91Copper ContributorThanks for your help