Results 1 to 10 of 10

Loops and Dates

Threaded View

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

    Loops and Dates

    Hi all, I am stumped with a problem involving a loop that searches back 1 week. As it is, my loop will search each cell looking for the date that is 7 days ago. It works fine until it finds that the date is not there. For example, 7 days ago was a Canadian holiday and therefore no update was made to my spreadsheet on the 1st of July. Being that, my loop skips right past and procedes to the top of the page and right into a runtime error. Basically, I need to implement a code that says: If the date does not exist, then stop on the day following (eg July 2). Here is my code:

    Dim CurrentDate As Date
        Dim CompareDate As Date
        Application.Worksheets("CdnDaily").Select
        Range("CdnDailyDate").End(xlDown).Select
        CurrentDate = ActiveCell.Value
        CompareDate = CurrentDate - 7
        Do While ActiveCell.Value <> CompareDate
            ActiveCell.Offset(-1, 0).Select
        Loop
    I hope this is clear enough, please let me know if you need more.

    Cheers:

    Mordred
    Last edited by Mordred; 07-13-2010 at 05:22 PM. Reason: It is Solved

Thread Information

Users Browsing this Thread

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

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