Solved

Return a unique row from a subset that has duplicates in a specified column, based on the latest date of another spcecified column

Posted on 2011-09-10
5
230 Views
Last Modified: 2012-08-14
I'm working in Excel 2007.  I have a table in which a particular column will have duplicates; I need to report one of the rows with the duplicates but the row that remains must be determined by a date in another column.  

See the attachment.  The first row should remain because there is no duplicate in the EPD_IDENTIFIER column.  The next two rows have a duplicate in the EPD_IDENTIFIER column but I need only the row with the latest time stamp in the EPD_STATUS_CHANGE_TS column to remain.  All the rows with a red arrow should remain, the other deleted.

example.pptx
0
Comment
Question by:wkraft
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
wkraft,

It will be much, much more helpful if you provide a sample Excel file.  Sending a PowerPoint file for an Excel problem won't do us much good :)

Patrick
0
 

Author Comment

by:wkraft
Comment Utility
Thanks for pointing that out, Patrick.  Makes a lot of sense.  

I've attached the data in an Excel spreadsheet to this comment.
--example-again.xlsx
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
Please try uploading the file again, it does not seem to have been uploaded correctly.
0
 

Accepted Solution

by:
wkraft earned 0 total points
Comment Utility
With the page filtered newest to oldest by EPD_STATUS_CHANGE_TS, then A to Z by EPD_IDENTIFIER, run macro:


Public Sub CorrectList()

Dim lastRow As Integer, EPD As String, nextEPD As String, count As Integer, canc As Integer

lastRow = Cells(Rows.count, "A").End(xlUp).Row

For i = 2 To lastRow
   
    EPD = Cells(i, "C")
    count = 1
   
    If EPD = "" Then
   
        Exit For
       
    End If
   
    can = 0
   
    If Cells(i, "D") = "CANCELLED" Then
        can = 1
    End If
   
    For t = i + 1 To lastRow
            nextEPD = Cells(t, "C")
        If EPD = nextEPD Then
             count = count + 1
        Else: Exit For
       
        End If
    Next
   

   
    Select Case can
       
        Case 0
               
                If count <> 1 Then
                    Rows(i + 1 & ":" & i + count - 1).Select
                    Selection.Delete Shift:=xlUp
                End If
               
        Case 1
                               
                    Rows(i & ":" & i + count - 1).Select
                    Selection.Delete Shift:=xlUp
                    i = i - 1
    End Select
   
Next

End Sub
0
 

Author Closing Comment

by:wkraft
Comment Utility
Coworker was able to help build a macro.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now