Remove duplicate rows based on earlier date

tpmccarthy

New Member
Joined
Aug 2, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
I have duplicate records that differ only by date. I want to identify the dupes (FN/LN) and remove the record with the earlier date.
I inherited the input process and can't screen the records at input.

Date First Last .....
4/8/22 14:56 Thomas McCarthy .....
4/19/22 2:56 Thomas McCarthy ......

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Tpmccarthy,
Maybe this?
VBA Code:
Sub RemoveDuplicates()
    Application.ScreenUpdating = False
    Dim CntRecs As Long
    CntRecs = Range("A1").Offset(Rows.Count - 1, 0).End(xlUp).Row
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _
        "B1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _
        "A1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortTextAsNumbers
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range(Range("A1"), Range("B1").Offset(CntRecs - 1))
        .Apply
    End With
    ActiveSheet.Range(Range("A1"), Range("B1").Offset(CntRecs - 1)).RemoveDuplicates Columns:=2, Header:=xlYes
End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    95.7 KB · Views: 5
Upvote 0
Thanks. I may not have explained properly (I'm just getting back into this stuff in a number of years)
I want to remove the entire row if B (first name) and C (Last name) match. I need to KEEP the record with the later date.

Datef namel name
4/8/22 14:56 ThomasMcCarthy
5/19/22 2:15ThomasMcCarthy
 
Upvote 0
Hi T@pmccarthy,
Maybe this?
VBA Code:
Sub RemoveDuplicates_FL_Nms()
    Application.ScreenUpdating = False
    Dim CntRecs As Long
    CntRecs = Range("A1").Offset(Rows.Count - 1, 0).End(xlUp).Row
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _
        "B1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _
        "C1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _
        "A1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortTextAsNumbers
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range(Range("A2"), Range("C2").Offset(CntRecs - 2))
        .Apply
    End With
    ActiveSheet.Range(Range("A1"), Range("C1").Offset(CntRecs - 1)).RemoveDuplicates Columns:=Array(2, 3), Header:=xlYes
End Sub

[ATTACH type="full"]62351[/ATTACH]
 

Attachments

  • Capture.JPG
    Capture.JPG
    73.1 KB · Views: 4
Upvote 0
Solution
You are very welcome, I'm happy to make you feel happy and satisfied.:)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,847
Members
449,051
Latest member
excelquestion515

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