+ Reply to Thread
Results 1 to 5 of 5

For Loop + Date

  1. #1
    Registered User
    Join Date
    07-21-2011
    Location
    Pocahontas, IL
    MS-Off Ver
    Excel 2003
    Posts
    3

    For Loop + Date

    Hello all,

    I have a workbook that I will be storing each sheet as a date, however i convert the date to 7-21-11 since I can not use / inthe name of the sheet. Then I covert it back to a date and using the code below it will not pickup the if statement.

    My goal is to delete a worksheet if it is X amount of days old.

    Please Login or Register  to view this content.
    Last edited by jhensler01; 07-21-2011 at 04:23 PM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: For Loop + Date

    Hi jhensler01 and welcome to the forum. Please take a moment to read the forum rules located here and wrap your code with code tags as per Rule #3. Once you do that, someone will be able to help you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    07-21-2011
    Location
    Pocahontas, IL
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: For Loop + Date

    Thank you! I will look them over.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: For Loop + Date

    jhensler01,

    Give the following a try. The Sub calls the Function 'isOld' to check if the worksheet name is a date and if that date is older than the DaysToKeep. If the function returns True, then the worksheet gets deleted, otherwise the macro moves to the next sheet until all sheets have been checked
    Please Login or Register  to view this content.


    Hope that helps,
    ~tigeravatar

  5. #5
    Registered User
    Join Date
    07-21-2011
    Location
    Pocahontas, IL
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: For Loop + Date

    ---edit--
    sorry your code did work for this.. thank you


    Thanks for the help though!
    Jason
    Last edited by jhensler01; 07-21-2011 at 04:53 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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