IAAMOATGTIL
New Member
- Joined
- Jan 14, 2017
- Messages
- 5
Can you put a stopwatch in Excel that starts when a checkbox is ticked and resets when the checkbox is unticked? And finally, stops when another checkbox is ticked?
Option Explicit
Dim CountDown As Date
Sub Timer()
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Reset"
End Sub
Sub Reset()
Dim count As Range
Set count = [A1] ' A1 contains the number of seconds for the countdown.
count.Value = count.Value - 1
If count <= 0 Then
MsgBox "Countdown complete."
Exit Sub
End If
Call Timer
End Sub
Sub DisableTimer()
On Error Resume Next
Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False
End Sub
Sub clrAll()
Sheets("Sheet1").Range("A1").Value = ""
End Sub
The simple answer is yes.
Here is a project for you to view and experiment with. You'll need to change the CommandButtons to Checkboxes to fire the macros.
Download : https://www.amazon.com/clouddrive/s...eRt8eu42inGBz33mSi?ref_=cd_ph_share_link_copy
Code:Option Explicit Dim CountDown As Date Sub Timer() CountDown = Now + TimeValue("00:00:01") Application.OnTime CountDown, "Reset" End Sub Sub Reset() Dim count As Range Set count = [A1] ' A1 contains the number of seconds for the countdown. count.Value = count.Value - 1 If count <= 0 Then MsgBox "Countdown complete." Exit Sub End If Call Timer End Sub Sub DisableTimer() On Error Resume Next Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False End Sub Sub clrAll() Sheets("Sheet1").Range("A1").Value = "" End Sub