Excel Macro to Delete dups based on date

tuxham

New Member
Joined
Apr 25, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I'm trying to create an excel macro that can delete duplicate rows but keeps the original one based on the oldest date.

In the table below you will find the example data and the output for which I'm looking. I need to delete all duplicate rows but keep the oldest one based on the date column.

1682437513461.png
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try

VBA Code:
Sub dele()
        Dim wk As Worksheet: Set wk = ActiveSheet
        
        With wk.Range("A1").CurrentRegion
            .Sort key1:=Range("C1"), order1:=xlAscending, Header:=xlYes
            .RemoveDuplicates 2, xlYes
        End With
End Sub
 
Upvote 1
Solution
Try

VBA Code:
Sub dele()
        Dim wk As Worksheet: Set wk = ActiveSheet
       
        With wk.Range("A1").CurrentRegion
            .Sort key1:=Range("C1"), order1:=xlAscending, Header:=xlYes
            .RemoveDuplicates 2, xlYes
        End With
End Sub
That worked
 
Upvote 0
Try

VBA Code:
Sub dele()
        Dim wk As Worksheet: Set wk = ActiveSheet
       
        With wk.Range("A1").CurrentRegion
            .Sort key1:=Range("C1"), order1:=xlAscending, Header:=xlYes
            .RemoveDuplicates 2, xlYes
        End With
End Sub
Thank you so much
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,075
Members
449,205
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top