Simple Timer facility
"Victor Delta" wrote:
In a large Excel spreadsheet, I am looking to add
a simple timer which will, when started, put say a
'Y' in a cell for 1 hour. No countdown display or anything complicated
needed.
Untested; there might be syntax errors.
Dim endtime as Double ' global to module
Sub startIt()
Range("A1") = "Y"
endTime = Now + TimeSerial(1,0,0) ' note: one-second resolution
Application.OnTime endTime, "stopIt"
End Sub
Sub stopIt()
Range("A1").ClearContents
On Error Resume Next
Application.OnTime endTime, "stopIt",, False
End Sub
The OnError and OnTime/False statements allow stopIt to double as a way to
abort the time-out event before the 1-hour deadline, if you wish.
That is also the reason for putting the time-out deadline into a global
variable (endTime).
|