+ Reply to Thread
Results 1 to 6 of 6

Delete duplicate rows containing the oldest date and time entries

  1. #1
    Registered User
    Join Date
    04-27-2014
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    22

    Delete duplicate rows containing the oldest date and time entries

    Hi,

    I'm new to the forum and have only a basic understanding of vba.

    I have a UserForm which writes data to rows in a master spreadsheet. I'm attempting to write some vba code for a CommandButton in the master spreadsheet which can identify and delete duplicate entries based on "user ID", "Date", and "Time". I would like the CommandButton to retain the most recent entry from a user and delete all previous entries.

    My master sheet is set out as such...
    A, B, C, D,
    UserID, Date, Time, Response

    The users could potentially submit multiple entries on the same day. Ideally I would like to be able to click a CommandButton and delete each user's submission but retain their most recent one (based on "UserID", then "Date", then "Time").

    I've searched all day for a solution and I've come close but I can not figure out a code that accounts for my three variables ("UserID", then "Date", then "Time").

    I've attached a sample worksheet in case anyone is able to help.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Delete duplicate rows containing the oldest date and time entries

    Hi 180drop,

    Welcome to the forum!!

    As long as the data is sorted in the way as your posted sample file, try this (initially on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    04-27-2014
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Delete duplicate rows containing the oldest date and time entries

    Thanks for the quick response and the code Robert!

    The code is working, although not quite in the way I was hoping for. This is maybe my fault as I might not have given you enough info to work with. Your code appears to be identifying duplicate entries made on the same date (column B) and then deleting the oldest entries for that date based on the time in column C. If the user then submits another entry the next day, the code appears to retain 2 entries for the same user (presumably because they have different dates).

    The users could potentially submit many entries over a period of months. If possible I would like the CommandButton to delete every previous user submission except the latest one for each user. The end result should be that the spreadsheet contains only 1 submission (the most recent one) from each user. I've attached an updated spreadsheet with a few more entries on in case you need further info.

    Thanks again for your help. It's greatly appreciated.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Delete duplicate rows containing the oldest date and time entries

    Hi there,

    Again, as long as the data is sorted in the same way as the posted example, just replace this line of code...

    Please Login or Register  to view this content.
    ...with this:

    Please Login or Register  to view this content.
    Robert

  5. #5
    Registered User
    Join Date
    04-27-2014
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Delete duplicate rows containing the oldest date and time entries

    Hi Robert,

    Solved! I've added your new line of code and it works like a charm. This is exactly what I was looking for.

    I can't thank you enough for the help & quick responses. You wouldn't believe the amount of time I've spent trying to get this result.

    Very much appreciated.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Delete duplicate rows containing the oldest date and time entries

    Hi 180drop,

    Thanks for letting us know and for marking the thread as solved. I'm glad I was able to come up with a workable solution for you.

    Regards,

    Robert

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Stocklist - Combine Duplicate entries, Delete rows
    By ibs2012 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2013, 05:56 AM
  2. [SOLVED] Delete duplicate entries
    By ZeDoctor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2012, 11:18 AM
  3. Delete duplicate rows, but keep the cell that has the latest date
    By vaznlyfe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 01:35 PM
  4. Display Date and Time of oldest item in Mailbox
    By fcomino in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2010, 12:11 AM
  5. [SOLVED] I want to delete rows with duplicate entries within one column.
    By kini olegario in forum Excel General
    Replies: 1
    Last Post: 01-14-2005, 10:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1