Half-hour countdown timer issues

uniden32

New Member
Joined
Sep 19, 2010
Messages
22
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)

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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,609
Messages
6,179,877
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top