Consulting

Results 1 to 2 of 2

Thread: OnTime reschedule based on cell date days from today

  1. #1
    VBAX Regular
    Joined
    Apr 2012
    Posts
    22
    Location

    OnTime reschedule based on cell date days from today

    The code below is supposed to look at the date in cell "B2" and determine when to reschedule the macro based on how many days the date in cell "B2 is from today. I can't get the code to perform anything other than the "Case 0 To 0" ontime option regardless of the date in cell "B2". I added the line of code [VBA]ActiveSheet.Range("c3") = iDaysDiff[/VBA] to find out that "iDaysDiff" always results in "0" no matter what the date is in cell "B2". This explains why the "Case 0 To 0" ontime option is always performed, but I would like the "iDaysDiff" to result in the number of days from the date in "B2" to today instead of always resulting in "0". The date in cell "B2" is in the month/day/year date format.


    [VBA]Sub Macro1()

    'Code
    'Code
    'Code

    Dim dt As Date
    Dim iYear As Integer
    Dim iMonth As Integer
    Dim iDay As Integer
    Dim iDaysDiff As Integer
    dt = Sheet1.Cells(2, 2)
    iDay = Day(Now)
    iMonth = Month(Now)
    iYear = Year(Now)
    iDaysDiff = dt - DateSerial(iYear, iMonth, iDay)
    ActiveSheet.Range("c3") = iDaysDiff
    Select Case iDaysDiff
    Case 0 To 0
    Application.OnTime Now + TimeValue("00:00:30"), "Macro1"
    Case 1 To 2
    Application.OnTime Now + TimeValue("00:01:00"), "Macro1"
    End Select


    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Sub Macro1()

    'Code
    'Code
    'Code

    Dim dt As Date
    Dim iDaysDiff As Integer

    dt = Sheet1.Cells(2, 2)
    iDaysDiff = dt - Date
    ActiveSheet.Range("c3") = iDaysDiff
    Select Case iDaysDiff
    Case 0
    Application.OnTime Now + TimeValue("00:00:30"), "Macro1"
    Case 1 To 2
    Application.OnTime Now + TimeValue("00:01:00"), "Macro1"
    End Select
    End Sub [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •