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
231 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Formula 6 46
splitting text of cell to columns 14 24
Boolean help 6 27
Get details of a Background Image applied to a sheet in excel 7 11
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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.

911 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

21 Experts available now in Live!

Get 1:1 Help Now