+ Reply to Thread
Results 1 to 5 of 5

Macro to filter based on the latest three (3) dates for each identical name

  1. #1
    Registered User
    Join Date
    08-15-2019
    Location
    USA, California
    MS-Off Ver
    MS Office PRO Plus 2016
    Posts
    2

    Question Macro to filter based on the latest three (3) dates for each identical name

    I have a large spreadsheet with names and dates. I need to be able to filter and keep only the latest 3 dates for each name and the rest can be deleted. If I it is not possible to delete them, if I could just highlight the latest 3 dates, that would suffice.... with the caveat that some names may only have 1 or 2 dates, which in that case, those would be left as is. Below is a small example of what I have and then what the outcome should be if possible. Any help or ideas would be greatly appreciated.

    BEFORE:

    Capture1.JPG

    AFTER:

    Capture2.JPG

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    Quote Originally Posted by lxnliz View Post
    keep only the latest 3 dates for each name
    As your after picture does very not match that ! Or we have not the same definition of 'latest 3 dates' …

    According to forum rules, far better than a picture is a workbook attachment with before & after sheets.

  3. #3
    Registered User
    Join Date
    08-15-2019
    Location
    USA, California
    MS-Off Ver
    MS Office PRO Plus 2016
    Posts
    2

    Re: Macro to filter based on the latest three (3) dates for each identical name

    Marc - Yes, something went wrong with the sorting of the dates before I captured the image, so the 2nd image is incorrect. I'm sure the definition of latest (recent) is the same That being said, I have figured out an easier way to solve my issue...

    After sorting the dates appropriately from most recent (newest) to oldest, I run a macro that adds a sequential numeric value for each time the same name is encountered ie: 1,2,3,4 etc. Then the numbering starts over for the next distinct name. After that, I just filter on the newly added number column to show only 1,2,3 and voila! I have the 3 most recent dates.

    Macro I used:

    Please Login or Register  to view this content.
    Last edited by AliGW; 08-16-2019 at 04:04 AM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Instead of your code just with an EZ formula …

    To delete rows, another EZ formula in a helper column if the number is > 3,
    then sort on this helper column then clear all the TRUE rows …

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Macro to filter based on the latest three (3) dates for each identical name

    @Ixnliz

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new here, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. VBA- Filter Pivot table based on latest and 2nd latest date in column
    By ziyan89 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 12-29-2015, 11:18 AM
  2. Make macro choose latest between multiple possible dates
    By esc952 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2015, 04:16 AM
  3. Macro to filter based on two dates and key word
    By swk8429 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2015, 10:13 AM
  4. [SOLVED] Macro To Filter Dates Based On Data In Selected Cell
    By SilverFox in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2012, 08:45 AM
  5. Replies: 2
    Last Post: 07-10-2012, 02:10 AM
  6. Replies: 3
    Last Post: 01-11-2012, 03:37 AM
  7. Macro to filter based on identical column data as opposed to entire record
    By marielb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2007, 12:27 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