Skip to main content

How to remove duplicate rows but keep the one with latest date in Excel?

doc remove duplicates keep recent 1

I have a range of data which contains some duplicate values in column A, and in column B is populated with some date, now, I need to remove the duplicate rows in column A but keep the latest date from corresponding column B as following screenshot shown, do you have any good ideas to solve this problem in Excel quickly and easily?

Remove duplicate values and keep most recent date in another column with VBA code

Remove duplicate values and keep most recent date in another column with Kutools for Excel


Remove duplicate values and keep most recent date in another column with VBA code

The following VBA code may help you to remove the duplicate cells and keep the latest date from another column, please do as follows:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and then paste the following macro in the Module Window.

VBA code: Remove duplicate values and keep the most recent date

Sub test()
'updateby Extendoffice 
    Dim xRng As Range
    Dim xTxt As String
    On Error Resume Next
    xTxt = Application.ActiveWindow.RangeSelection.Address
    Set xRng = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRng Is Nothing Then Exit Sub
    If (xRng.Columns.Count < 2) Or (xRng.Rows.Count < 2) Then
        MsgBox "the used range is invalid", , "Kutools for Excel"
        Exit Sub
    End If
    xRng.Sort key1:=xRng.Cells(1, 1), Order1:=xlAscending, key2:=xRng.Cells(1, 2), Order2:=xlDescending, Header:=xlGuess
    xRng.RemoveDuplicates Columns:=1, Header:=xlGuess
End Sub

3. Then press F5 key to execute this code, and a prompt box will pop out to remind you select the data range that you want to use, see screenshot:

doc remove duplicates keep recent 2

4. And then click OK, the duplicate values in column A have been removed and the latest date in column B is kept as you need. See screenshot:

doc remove duplicates keep recent 3

Note: To apply the above code successfully, the column contains duplicate values must be located at the left of the date column.


Remove duplicate values and keep most recent date in another column with Kutools for Excel

If you are not familiar with the code, please don’t worry, the powerful utility- Advanced Combine Rows of Kutools for Excel may help you to solve this task with an ease.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. 

After installing Kutools for Excel, please do as follows:

1. Select the data range that you want to remove duplicates and keep the most recent date from another column.

2. Then click Kutools > Merge & Split > Advanced Combine Rows, see screenshot:

3. In the Combine Rows Based on Column dialog box, click the column name that you want to remove the duplicate values, then click Primary key, see screenshot:

doc remove duplicates keep recent 5

4. Go on clicking another column name which you want to keep the most recent date, and then click Calculate > Max, see screenshot:

doc remove duplicates keep recent 6

5. And then click Ok button to close this dialog, and now, you can see the duplicate names in column A have been removed and only keep the latest date in corresponding column B, see screenshot:

doc remove duplicates keep recent 7

Download and free trial Kutools for Excel Now !


Demo: Remove duplicate values and keep most recent date in another column with Kutools for Excel

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Best Office Productivity Tools

Supports Office/Excel 2007-2021 and 365  |  Available in 44 Languages  |  Easy to Uninstall Completely

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...

Supercharge Your Excel Skills: Experience Efficiency Like Never Before with Kutools for Excel  (Full-Featured 30-Day Free Trial)

kte tab 201905

60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day! (Full-Featured 30-Day Free Trial)
60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 
 
Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hola A ver si me pueden ayudar con lo siguiente. Tengo una columna con fechas de ingreso de material, otra con los materiales que se van repitiendo y otra columna con el numero del documento de despacho. Necesito que para un mismo numero de documento de despacho o bien, de fecha, no se duplique el material. Sin embargo en la columna de materiales se deben repetir los materiales, pero no deben duplicarse para la misma fecha o bien para el mismo numero de documento. Se requiere macro?
This comment was minimized by the moderator on the site
Hola
A ver si me pueden ayudar con lo siguiente.

Tengo una columna con fechas de ingreso de material, otra con los materiales que se van repitiendo en la tabla y otra con el numero del documento de despacho.

Necesito que para un mismo numero de documento de despacho o bien, de fecha, no se duplique el material. Sin embargo en la columna de materiales se deben los materiales, pero no deben duplicarse para la misma fecha o bien para el mismo numero de documento.

Se requiere macro?

Adjunto tabla tipo.




Gracias!!
This comment was minimized by the moderator on the site
This was extremely helpful! Thanks so much!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations