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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
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.
 

Forum statistics

Threads
1,141,924
Messages
5,709,375
Members
421,633
Latest member
Ubergribbler

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
Top