ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do i stop a clock in excel (https://www.excelbanter.com/excel-programming/443295-how-do-i-stop-clock-excel.html)

accsys

How do i stop a clock in excel
 
Hello,

I have a clock macro in an excel worksheet that I would like it to stop when
it
hits 5:30PM each day. How would I make this possible?

This is what i have so far:

Sub StartTiming()

Call StartClock

With ThisWorkbook.Sheets("Sheet1")
'Clear total elapsed time
.Range("j3").ClearContents

'Format the cells with time formats
.Range("j1:j3").NumberFormat = "hh:mm:ss"

'Save the start time in cell J1
.Range("j1").Value = Range("j2").Value

End With

End Sub

Sub StartClock()

With ThisWorkbook.Sheets("Sheet1")
.Range("j1") = Now()
End With

NextTick = Now + TimeValue("00:00:01")

Application.OnTime NextTick, "StartClock"
End Sub

Sub StopClock()
'Stop OnTime event.
'Returns error if already stopped and hense the on error handling.
On Error Resume Next

Application.OnTime _
EarliestTime:=NextTick, _
Procedu="StartClock", _
Schedule:=False

If Err.Number > 0 Then Exit Sub

On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("j3").Value _
= .Range("j2").Value - .Range("j1").Value
End With

End Sub


All times are GMT +1. The time now is 10:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com