Try
Code:Dim NextTick As Date, t As Date Sub StartClock() If Range("IV1").Value = True Or Range("IV1").Value = "" Then t = Time Else t = Time - Range("IV2").Value End If Call TickTock End Sub Private Sub TickTock() Range("A1").Value = Format(Time - t, "hh:mm:ss") NextTick = Now + TimeValue("00:00:01") Application.OnTime NextTick, "TickTock" End Sub Sub StopClock() Range("IV1").Value = False Range("IV2").Value = Range("A1").Value On Error Resume Next Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False On Error GoTo 0 End Sub Sub Reset() Call StopClock Range("A1").Value = 0 Range("IV1").Value = True Range("IV2").ClearContents End Sub
Try in a regular module
Code:Dim NextTick As Date, t As Date Sub StartClock() t = Time Call TickTock End Sub Private Sub TickTock() Range("A1").Value = Format(Time - t, "hh:mm:ss") NextTick = Now + TimeValue("00:00:01") Application.OnTime NextTick, "TickTock" End Sub Sub StopClock() Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False End Sub Sub Reset() Call StopClock Range("A1").Value = 0 End Sub
You can assign StartClock, StopClock and Reset to buttons from the Forms toolbar.
If the stopwatch is already stopped, then calling the stopclock sub causes an error. Is there a way to have it check first, and if already stopped, then calling the sub again wont crash it. The reason I ask is the start and stop are associated with other buttons in a form, and the end user might have to click 2 buttons in some scenarios, both which would stop the clock on their own, yet only one button might be needed in other scenarios. Thanks