Issue I'm having is that when the timer initially starts, everything is computed correctly, timer works great.
When the countdown timer hits zero, I have it restart from the beginning, but the timer usually starts off at 23-25 minutes, instead of 30 minutes.
Data sheet formulas:
D2 - Time (value is sent here in StartTimer .Value = Time)
D3 - =Hour(D2)
D4 - =Minute(D2)
D5 - =Second(D2)
E4 - =IF($D$4>=30,59-$D$4,29-$D$4)
E5 - =SUM(60-$D$5)
(The formulas in E4 and E5 are used to determine whether I'm counting down to the top of the our or down to the bottom of the hour)
When the countdown timer hits zero, I have it restart from the beginning, but the timer usually starts off at 23-25 minutes, instead of 30 minutes.
Data sheet formulas:
D2 - Time (value is sent here in StartTimer .Value = Time)
D3 - =Hour(D2)
D4 - =Minute(D2)
D5 - =Second(D2)
E4 - =IF($D$4>=30,59-$D$4,29-$D$4)
E5 - =SUM(60-$D$5)
(The formulas in E4 and E5 are used to determine whether I'm counting down to the top of the our or down to the bottom of the hour)
Code:
Dim NextTick As Date
Sub StartTimer()
With ThisWorkbook.Sheets("Data").Range("D2")
.NumberFormat = "hh:mm:ss"
.Value = Time
End With
Call FormatTime
Call TickTock
End Sub
Private Sub FormatTime()
With ThisWorkbook.Sheets("Sheet1").Range("D4")
.NumberFormat = "mm:ss"
.Value = ThisWorkbook.Sheets("Data").Range("E3")
End With
End Sub
Private Sub TickTock()
With ThisWorkbook.Sheets("Sheet1").Range("D4")
.NumberFormat = "mm:ss"
.Value = ThisWorkbook.Sheets("Sheet1").Range("D4")
.Value = .Value - (1 / 86400)
If .Value <= (1 / 86400) Then
Beep
Call StopClock
Call StartTimer
End If
End With
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "TickTock"
End Sub
Sub StopClock()
On Error Resume Next
Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False
On Error GoTo 0
End Sub