Search code examples
excelexcel-formulaexcel-2007

How do I find and delete same cells in column, with different dates, so I will be able to save the date closest to present


I'm in a dilemma, and I need help. So here it goes. I have a single sheet with 2 columns, in column one are Part Numbers, whereas there are duplicates, in column 2 are their released dates.

I already know how to identify duplicates using =COUNTIF, my problem is, I want to delete the duplicates with dates furthest from the present date. How can I do it?

Please help

#       Date        Duplicate 
AB12345 4/27/2015   TRUE  ------> I want to automatically delete/highlight this
BC23456 6/27/2015   FALSE
DE12346 5/2/2015    FALSE
AB12345 11/30/2015  TRUE  ------> I want to automatically delete/highlight this
AB12345 3/13/2016   TRUE  ------> So that this will remain.        

Solution

  • This is simple. You need to select all of the data, and sort it date Newest to Oldest (so that the ones that you want to keep are sorted first).

    Then, keeping the selection on both columns, use Excel's 'remove duplicates' (in the Data tab). In the pop-up box, make sure that only the Part Number box is ticked.

    Excel will iterate through, and remove duplicates, but the algorithm will always remove the lower of any two identical values, so your initial sort by date will allow you to achieve the result that you wanted.