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
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

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,026
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,114,096
Messages
5,545,926
Members
410,713
Latest member
TaremyLunsil
Top