+ Reply to Thread
Results 1 to 5 of 5

Delete the oldest repeat

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Delete the oldest repeat

    Hi Guys,

    I have to monitor the training completion rates. Unfortunately, the reporting extract is less than ideal, with repeats etc.

    The participants are meant to put their employee number in, but that doesn't always happen.

    I'm looking for a way to manage this dynamic list (the number of records is likely to change)
    I want to:
    1. Delete anything in Column I that isn't "Passed"
    2. Look for duplicates in Column G and for each duplicate, delete the oldest based on the value in column B
      • Delete the entire row of the oldest duplicate
      • Unfortunately, not all employee numbers are completed. I'm happy for a control column concatenating Column E and Column F instead

    I've attached a sanitised workbook with two tabs - "Base Data" and "Intended Outomce"
    • "Base Data" is indicative of how I would receive the data
    • "Intended Outcome" is how I want it to look after the manipulation is complete

    I would also be grateful if you could comment the life out of any VBA so I can read and, hopefully, learn.

    Thanks all

    MagicMan
    Attached Files Attached Files

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Delete the oldest repeat

    Assuming that the records are already ordered by date (i.e. oldest to newest), this might work for you:

    Please Login or Register  to view this content.
    Suggest you run it on a copy of your base data!

    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete the oldest repeat

    Here's another option. It assumes the data is already sorted by column B descending. If not just add another instruction to the macro to sort it first.

    In general I prefer to avoid loops since they can be very time consuming and it's the most efficient way I know to do this sort of stuff.

    This approach :

    A. Identifies the number of Rows
    B. Creates helper column J which concatenates the last/First name
    C. Creates a formula in column K which identifies a duplicate name or <> "Passed"
    D. Filters column K for the word 'delete'
    E. Stops Excel halting to alert you about deleting
    F. Deletes all the filtered rows
    G. Removes the filter
    H. Deletes the helper columns J & K


    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Delete the oldest repeat

    WBD and Richard,

    Thank you very much for your input. I've added to both of your reps.

    I used WBD's because it was first in (I'm not unduly concerned about length of time to execute), but it would be interesting to test our Richard's solution to see what it does in terms of time difference to operate.

    I'm planning on assigning the macro to a button on a front sheet. Do I simply need to activate the "Base Data" sheet as the first step (i.e. simply put Sheets("Base Data").Activate at the beginning of the macro.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Delete the oldest repeat

    You could do that or you could use this modified version:

    Please Login or Register  to view this content.
    WBD

+ 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. Macro to backup workbook and delete oldest file
    By tfilipe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2018, 03:23 PM
  2. [SOLVED] kEEP NEWEST ROWS AND DELETE OLDEST ONE IF
    By ozstrik3r69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2017, 08:52 AM
  3. Excel VBA To delete duplicates with oldest date
    By Helgard25 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2015, 09:44 AM
  4. Event based timestamp - after x number of entries delete oldest
    By rblissett in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-25-2014, 02:20 PM
  5. [SOLVED] Delete duplicate rows containing the oldest date and time entries
    By 180drop in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2014, 05:48 AM
  6. Automatic email sender that only sends 2 oldest reord and then delete them
    By ayan1988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2013, 04:43 PM
  7. Delete oldest duplicates
    By Pindacko in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-20-2007, 10:18 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