A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
--- schnipp ---
Option Explicit
Private Sub CommandButton1_Click()
'Starts the timer
'Setup the cell where the timer is shown
Set TimerCell = Range("A1")
'Setup the cell where the timer get the countdown value
Set TimerValue = Range("B1")
'Force timer to reset
EndTime = 0
'Keep timer running
StopTimer = False
'Call our timer
TimeCounter
End Sub
Private Sub CommandButton2_Click()
'Stops the timer
StopTimer = True
End Sub
--- schnapp ---
Add a normal module to your project and insert this code in there:
--- schnipp ---
Option Explicit
Public TimerCell As Range
Public TimerValue As Range
Public StopTimer As Boolean
Public EndTime As Double
Public Sub TimeCounter()
If Not StopTimer Then
If EndTime - Now < 0 Then
EndTime = Now + TimeSerial(0, TimerValue, 0)
End If
Application.EnableEvents = False
TimerCell = EndTime - Now
Application.EnableEvents = True
Application.OnTime Now + TimeSerial(0, 0, 1), "TimeCounter"
End If
End Sub
--- schnapp ---
Andreas.
I love this code. I like that I can change cells while the macro is running. Is there a way to make this without the loop? I was wondering if rather than the count starting over at 0, if it could have a pop-up message that says "Countdown Complete" instead?