countdown timer

don matteo

Board Regular
Joined
Nov 14, 2016
Messages
51
Hey guys i have taken some code from online to create a countdown timer
and when it hits 00:00:00 a msg box pops up
but i want the box to pop up when the timer hits 00:05:00 (5 min remaining )
can anyone help?
thanks
Code:
Public gCount As Date
Sub Timer()
gCount = Now + TimeValue("00:00:01")
Application.OnTime gCount, "EndMessage"
End Sub
Sub EndMessage()
Dim xRng As Range
Set xRng = Application.ActiveSheet.Range("b10")
xRng.Value = xRng.Value - TimeSerial(0, 0, 1)
If xRng.Value <= 0 Then
MsgBox "SEND COMM ASAP"
Exit Sub
End If
Call Timer
End Sub


Sub StopClock()
    Application.OnTime EarliestTime:=gCount, Procedure:="endmessage", Schedule:=False
   
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Rich (BB code):
Public gCount As Date
Sub Timer()

gCount = Now + TimeValue("00:00:01")
Application.OnTime gCount, "EndMessage"

End Sub
Sub EndMessage()

Dim xRng As Range

Set xRng = Application.ActiveSheet.Range("b10")
xRng.Value = xRng.Value - TimeSerial(0, 0, 1)
If xRng.Value <= TimeSerial(0, 5, 0) Then
    MsgBox "SEND COMM ASAP"
Else
    Call Timer
End If

End Sub
Sub StopClock()
    
Application.OnTime EarliestTime:=gCount, Procedure:="endmessage", Schedule:=False
   
End Sub

WBD
 
Upvote 0
thank you! this works
but how do i get the clock to continue counting down after you acknowledge the msg box?
 
Upvote 0
Sorry; I've been away.

Code:
Public gCount As Date
Sub Timer()

gCount = Now + TimeValue("00:00:01")
Application.OnTime gCount, "EndMessage"

End Sub
Sub EndMessage()

Dim xRng As Range

Set xRng = Application.ActiveSheet.Range("b10")
xRng.Value = xRng.Value - TimeSerial(0, 0, 1)
If xRng.Value <= TimeSerial(0, 5, 0) Then MsgBox "SEND COMM ASAP"

Call Timer

End Sub
Sub StopClock()
    
Application.OnTime EarliestTime:=gCount, Procedure:="endmessage", Schedule:=False
   
End Sub
 
Upvote 0
hey no problem
thank you but that code doesnt work, the msg box keeps popping up because its under 5 min
 
Upvote 0
Ah. Of course. OK.

Code:
Public timerCell As Range
Public nextEvent As Date
Public showMessage As Boolean
Public Sub StartTimer()

Set timerCell = Application.ActiveSheet.Range("B10")
showMessage = True
Call Timer

End Sub
Public Sub Timer()

nextEvent = Now + TimeSerial(0, 0, 1)
Application.OnTime EarliestTime:=nextEvent, Procedure:="EndMessage"

End Sub
Public Sub EndMessage()

timerCell.Value = timerCell.Value - TimeSerial(0, 0, 1)
If timerCell.Value <= TimeSerial(0, 5, 0) And showMessage Then
    MsgBox "SEND COMM ASAP"
    showMessage = False
End If

If timerCell.Value > 0 Then Call Timer

End Sub
Public Sub StopTimer()
    
Application.OnTime EarliestTime:=nextEvent, Procedure:="EndMessage", Schedule:=False
   
End Sub

Put the time value in B10 and call StartTimer.

WBD
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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