+ Reply to Thread
Results 1 to 9 of 9

VBA to delete all rows outside of date range

  1. #1
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    VBA to delete all rows outside of date range

    Hey Everyone,

    Im making a formatting macro with a lot of steps, one of the steps is deleting all rows that do not fall inside a set date range. It would be the date the report is being worked + 6weeks out. so I was using the date and dateadd feature to compensate for never having the exact date (report will be worked over and over until the end of time)

    this is what I have thus far, I am getting a sytax error on the if and portion. Im sure there is probably a more efficient way then going line by line but I am limited in my knowledge here. Any help would as always be greatly appreciated.

    Please Login or Register  to view this content.
    Thank you,

    Fawkes_
    Last edited by Fawkes_; 01-20-2017 at 01:44 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA to delete all rows outside of date range

    You need to end the line with [/code] in order for the code wrap to work.

  3. #3
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: VBA to delete all rows outside of date range

    Sorry, ctrl-V causing issues lol, should be good now.
    Last edited by Fawkes_; 01-20-2017 at 01:43 PM.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA to delete all rows outside of date range

    Possibly this should work for you,

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: VBA to delete all rows outside of date range

    Thank you for the guidance Davesexcel. I will give this a shot
    Last edited by Fawkes_; 01-20-2017 at 04:01 PM.

  6. #6
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: VBA to delete all rows outside of date range

    Well here is my completed code:

    Im trying to find a way to speed up the process now it takes about 10 min to complete.

    Also, I was wondering if during the selections after filtering if using ("S2:S") would cause issues with anything. Im concerned with the report being larger in the future. Perhaps I should start with a last row count and use that method? I want it to select down to the last cell in the specific range, but I'm pretty sure the S2:S will go till the last possible cell not the last filled cell. What do you think?

    Also, when doing the Vlook phase there is a long lull where it is linking to the file in the shared server, I was wondering if there was a way to speed that process up. 4 min of the process is the initial link to the second report that the vlook comes from

    As always thank you for any guidance I this endeavor.

    Please Login or Register  to view this content.
    Last edited by Fawkes_; 01-20-2017 at 06:36 PM.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA to delete all rows outside of date range

    Attach a sample workbook. 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.

  8. #8
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: VBA to delete all rows outside of date range

    Alright, well this isn't working.... what to do what to do.

    all of the trim mods are working except for the date mod. It just blows right through without deleting anything.

    I also adjusted all the final columns to LastRow and defined last row. so now that isn't an issue, however getting a code to delete something from todays date back and todays date plus 6 weeks forward... that's just not working out... any ideas?

    I'm noticing in my code that Date function is not going blue, which make me think it is not calling the date properly does this sound accurate? Also, I have been searching the Date add feature and I have not been able to find any way of its use where the "mm/dd/yyyy" section is replaced with a assigned date ie sdate in this code.

    maybe this isn't allowed?

    Calling out to the forum gods for assistance
    Last edited by Fawkes_; 01-25-2017 at 11:31 AM.

  9. #9
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: VBA to delete all rows outside of date range

    Well I came up with this and it seems to work, if anyone has any ideas let me know please.

    Please Login or Register  to view this content.

+ 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] Delete rows based on date range
    By hommeg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2015, 04:59 PM
  2. [SOLVED] Macro to find user input date range and delete everything outside range
    By sudric in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-13-2015, 11:52 AM
  3. 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
  4. [SOLVED] Extract date from cell and replace value with date then delete empty rows
    By jjislas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2013, 11:52 AM
  5. Macro, autofilter, delete rows outside date range, defined names as criteria
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2011, 04:10 AM
  6. Delete Rows based on date range.
    By ge0rge in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2009, 10:52 AM
  7. Delete rows based on date range entered?
    By fzrdiva in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-29-2006, 08:52 AM

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