Timer bypass

farmock

Board Regular
Joined
Sep 10, 2006
Messages
60
I have an application that is running on a timer every hour using the following code:
Application.OnTime TimeValue("01:00:00"), "procedure"

I would like to add an If statement so that if the time is between 9:00 PM
and 10:00 PM the timer will skip execution for that hour. I would appreciate any help you can provide. Thanks, Frank
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Like this?

Code:
If Time >= TimeSerial(21, 0, 0) And Time < TimeSerial(21, 0, 0) Then
   Application.OnTime Now + TimeValue("02:00:00"), "procedure" 
Else
   Application.OnTime Now + TimeValue("01:00:00"), "procedure" 
End If
 
Upvote 0
Andrew's kinda on the mark but not quite...at least by my interpretation of the OP's request.

Code:
If Time >= TimeSerial(21, 0, 0) And Time < TimeSerial(22, 0, 0) Then
Else
    'Do your stuff
    End If
Application.OnTime Now + TimeValue("01:00:00"), "procedure"
or
Code:
'Do your stuff
If Time >= TimeSerial(20, 0, 0) And Time < TimeSerial(21, 0, 0) Then
   Application.OnTime Now + TimeValue("02:00:00"), "procedure"
Else
   Application.OnTime Now + TimeValue("01:00:00"), "procedure"
End If
I prefer the former since it doesn't duplicate the OnTime statement.
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,538
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top