+ Reply to Thread
Results 1 to 5 of 5

Macro to delete rows that have a date outside 20 business day window

  1. #1
    Registered User
    Join Date
    06-26-2018
    Location
    us
    MS-Off Ver
    10
    Posts
    12

    Macro to delete rows that have a date outside 20 business day window

    Hi All,

    I have two sheets in my workbook. The 1st sheet is used to paste a data pull every morning, which is then interacts with some formulas. I then use thses formulas to send morning emails.

    I then copy all of Sheet1 and paste as values to Sheet2 (Queue History), so we have a historic record of every past pull. However, I only require the pulls from the last 20 business days. Therefore, I would like a macro that would delete (not just clear) every row on Sheet2 that has a date in column BW outside the last 20 business days. I also have 2 cells (Z1 and Z2) on a seperate page (Stats Email) that automatically update to reflect the beginning and end of the 20 day window.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Macro to delete rows that have a date outside 20 business day window

    First, I recommend you paste the data into an Excel Table. Excel tables have many benefits; among them are: they know how big they are so any formulas, pivot tables or charts built from them adjust automatically as you add or delete rows, they copy down automatically, formulas, formats and data validations.

    The way I would attack this is to delete the old data in the table and copy in the new data. Have a cell with the formula =Today()-20 and give it a name like Day20.

    In the table have a helper cell at the end with the formula [@[Date]] >= Day20. (or use cells Z1 and Z2 on the other sheet). This should evaluate to TRUE for any date within 20 days of the current day. When you delete the data in the table so you can paste in new data, the table will "remember" this formula and copy it down for each row in the new table.

    Then build a pivot table using this helper column as a filter set to TRUE.

    Some additional automation. Read the daily data automatically, clear the report table and copy paste the daily data. Take the results of the pivot table sheet, save it as a PDF and attach it to the emails. Of course also copy paste the new data to the archive.

    If you can provide two sample workbooks (data file) and (report file), we can get you set up.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    06-26-2018
    Location
    us
    MS-Off Ver
    10
    Posts
    12

    Re: Macro to delete rows that have a date outside 20 business day window

    Hi dflak, thanks for the response.

    The reason I would like to automatically delete the rows instead of just hiding them with a pivot table is because the sheet currently has over 5000 rows of data. Each morning data pull can contain up to 400 rows, so this page gets quite large and I would like to delete data older than 20 days to save space and speed up the workbook.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Macro to delete rows that have a date outside 20 business day window

    OK. In this case do exactly the same thing, then write a macro that goes from the last row to the first row step -1 looking at the helper column. When it finds FALSE (outside 20 days), delete the entire row.

  5. #5
    Registered User
    Join Date
    06-26-2018
    Location
    us
    MS-Off Ver
    10
    Posts
    12

    Re: Macro to delete rows that have a date outside 20 business day window

    Thank you!

+ 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. delete rows with date... HELP!! Macro
    By cory0789 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-02-2015, 06:48 PM
  2. Macro to delete certain rows if DATE criteria is met
    By lukasz_rz in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-28-2014, 11:30 AM
  3. Macro to delete certain rows if DATE criteria is met
    By lukasz_rz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2014, 01:16 PM
  4. RE: VBA Macro Needs Tweaking to Delete Rows Where Date As String is Less Than Today's Date
    By justinbelkin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-05-2013, 04:54 PM
  5. Macro to delete rows with date less than 01/01/12
    By jimstrongy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2012, 11:51 AM
  6. Replies: 3
    Last Post: 09-15-2011, 07:26 AM
  7. Macro required to delete rows based on date
    By jalalini in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2008, 03:27 AM

Tags for this Thread

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