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
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36516668
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
ID: 36516683
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
ID: 36516988
Please try uploading the file again, it does not seem to have been uploaded correctly.
0
 

Accepted Solution

by:
wkraft earned 0 total points
ID: 36516995
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
ID: 36541419
Coworker was able to help build a macro.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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.

691 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