Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hide Duplicate Records based on TimeStamp

Posted on 2013-06-28
5
Medium Priority
?
557 Views
Last Modified: 2013-06-29
Greetings

I have a data stream in to Excel Spreadsheets (1301, 1302, 1303, etc.) within a single Workbook. I have VBA routines to Delete Duplicate Records but they do not consider the TimeStamps. I need to "Hide" Records and not "Delete"

ColA               ColB               ColC               Cold
1/02/2013      CustA             data               data
1/13/2013      CustA             data               data
1/13/2013      CustB             data               data
1/08/2013      CustA             data               data
1/21/2013      CustB             data               data
1/13/2013      CustC             data               data
1/18/2013      CustB             data               data
1/13/2013      CustD             data               data

I need to "Hide" Records with earlier TimeStamps (ColA) by ColB (Customer)' I wish only to View a Customers Later Record based on TimeStamp (ColA). I must retail all data for a historical record.

ColA               ColB               ColC               Cold
1/13/2013      CustA             data               data
1/21/2013      CustB             data               data
1/13/2013      CustC             data               data
1/13/2013      CustD             data               data

This should run on Active Worksheet

Regards,

Dave
0
Comment
Question by:srlittle
[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 49

Accepted Solution

by:
Martin Liss earned 1200 total points
ID: 39286055
Here;s a macro.

Sub HideOld()
Dim lngLastRow As Long
Dim lngRow As Long
Dim lngCompareRow As Long
Dim strCust As String
Dim lngHighRow As Long
lngLastRow = Range("A65536").End(xlUp).Row

For lngRow = 2 To lngLastRow
    If Rows(lngRow & ":" & lngRow).EntireRow.Hidden = False Then
        strCust = Cells(lngRow, 2).Value
        lngHighRow = lngRow
        For lngCompareRow = lngRow + 1 To lngLastRow
            If Rows(lngCompareRow & ":" & lngCompareRow).EntireRow.Hidden = False Then
                If Cells(lngCompareRow, 2).Value = strCust Then
                    If DateValue(Cells(lngCompareRow, 1)) >= DateValue(Cells(lngHighRow, 1)) Then
                        Rows(lngHighRow & ":" & lngHighRow).EntireRow.Hidden = True
                        lngHighRow = lngCompareRow
                    Else
                        Rows(lngCompareRow & ":" & lngCompareRow).EntireRow.Hidden = True
                    End If
                End If
            End If
        Next
    End If
Next
    

End Sub

Open in new window

0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39286075
Note that the above assumes that your data starts in row 2.
0
 

Author Comment

by:srlittle
ID: 39286746
Took a while to walk thru your solution. Very nice. I learned a few things. Your code Hides Old Duplicates as expected, however the EntireRow.Hidden property does not allow me to Unhide the Hidden Rows from the Files/Unhide Button (It is grayed Out). However the Right Click "Unhide" works. I need to do this to view Historical Data. Your solution works and I accept with gratitude.

Regards,
Dave
0
 

Author Closing Comment

by:srlittle
ID: 39286758
My coding expertise is more centerd on data manipulation. I always enjoy learning more about the power of Workbook/Worksheet Properties and functions.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39286854
I'm not familiar with Files/Unhide but here's a companion macro you can use to unhide the rows. Do you know how to assign a shortcut key to the macro?

Sub ShowAll()

Dim lngLastRow As Long
lngLastRow = Range("A65536").End(xlUp).Row

Rows("1:" & lngLastRow).EntireRow.Hidden = False

End Sub

Open in new window

In any case I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

704 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