Remove Duplicate Lines; Retain Most Recent

jski21

Board Regular
Joined
Jan 2, 2019
Messages
155
Office Version
  1. 2016
Platform
  1. Windows
Good day Mr. Excel Team,

A rather sticky one here for me. As usual, canned system download reports are invariably ugly and unusable. Here's an excerpted sample:

Contracts_Certified_-_8006 (1).xlsx
ABCDEFGHIJKLMN
1GrantMajor ProgramMajor Program NameVendor Legal NameDoc Hdr Doc DescriptionDoc Hdr Record DateDoc Comm Service From DateDoc Comm Service To DateDoc IDObjectDoc Hdr Actual AmtDoc Hdr Open AmtDoc Hdr Closed AmtDoc Version No
21234567812345ABCDSTD Contractors Inc.J. Walk5/12/20216/29/202012/31/2021LA2020000000008638083,523.0049,328.0034,195.001
31234567812345ABCDSTD Contractors Inc.J. Walk6/24/20216/29/202012/31/2021LA2020000000008638083,523.0049,328.0034,195.002
41234567812345ABCDSTD Contractors Inc.J. Walk8/25/20226/29/202012/31/2021LA2020000000008638088,681.0035,239.0053,442.003
Grant Balances



The raw data represents a list of contracts and data related to that contract. For whatever reason, any change to a contract (amendment, etc.) results in the system creating another line for that contract and assigning it a sequential number. Contract number is in Column I (Doc ID). Sequential number is in Column N (Doc Version No). The duplication makes simple analysis unbearable as there is only one contract.

I'm attempting to develop a macro that would review Column I for dupes, glance over at Column N to see the sequence numbers, and have the entry with the highest sequence number survive. The other row entries would be deleted. End product would be one line for a contract, that one being the 'most recent.'

Thanks in advance for the consideration and review.

jski
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Please try the following on a copy of your workbook.
VBA Code:
Option Explicit
Sub jski21()
    Dim ws As Worksheet
    Set ws = Worksheets("Grant Balances")   '<-- *** Check the sheet name ***
    With ws.Range("A1").CurrentRegion
        .Sort Key1:=ws.Range("I1"), order1:=xlAscending, _
        Key2:=ws.Range("N1"), order2:=xlDescending, Header:=xlYes
        .RemoveDuplicates Columns:=9, Header:=xlYes
    End With
End Sub
 
Upvote 0
Solution
Awesome kevin9999. Walked through this using F8 and I see how this works now. Very helpful and instructive. Eliminated 700+ dupes. Huge time saver.

Thanks for your time and help!

jski
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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