Create A Stopwatch in Excel

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,501
Office Version
  1. 2016
Platform
  1. Windows
Hello To All,

How can i input a stopwatch in excel sheet with a Start, Stop, and Reset Button....

Awaiting reply,

Humayun
 
hello to All

i created this thread few days earlier and have managed to create a stopwatch with the help of VOG..

is there anyone who could let me know that how to display seconds into to nano or micro seconds..???

Current Format is 00:00:00 > (hh:mm:ss)

can the seconds be turned to 00:00:00000

Regards,

Humayun
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

I tried this also but got an error below. Can you help me with this?

virhe_zpsfc065152.png



Try

Code:
Dim NextTick As Date, t As Date

Sub StartClock()
If Range("IV1").Value = True Or Range("IV1").Value = "" Then
    t = Time
Else
    t = Time - Range("IV2").Value
End If
Call TickTock
End Sub

Private Sub TickTock()
Range("A1").Value = Format(Time - t, "hh:mm:ss")
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "TickTock"
End Sub

Sub StopClock()
Range("IV1").Value = False
Range("IV2").Value = Range("A1").Value
On Error Resume Next
Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False
On Error GoTo 0
End Sub

Sub Reset()
Call StopClock
Range("A1").Value = 0
Range("IV1").Value = True
Range("IV2").ClearContents
End Sub
 
Upvote 0
Try in a regular module

Code:
Dim NextTick As Date, t As Date

Sub StartClock()
t = Time
Call TickTock
End Sub

Private Sub TickTock()
Range("A1").Value = Format(Time - t, "hh:mm:ss")
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "TickTock"
End Sub

Sub StopClock()
Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False
End Sub

Sub Reset()
Call StopClock
Range("A1").Value = 0
End Sub

You can assign StartClock, StopClock and Reset to buttons from the Forms toolbar.

If the stopwatch is already stopped, then calling the stopclock sub causes an error. Is there a way to have it check first, and if already stopped, then calling the sub again wont crash it. The reason I ask is the start and stop are associated with other buttons in a form, and the end user might have to click 2 buttons in some scenarios, both which would stop the clock on their own, yet only one button might be needed in other scenarios. Thanks
 
Upvote 0
If the stopwatch is already stopped, then calling the stopclock sub causes an error. Is there a way to have it check first, and if already stopped, then calling the sub again wont crash it. The reason I ask is the start and stop are associated with other buttons in a form, and the end user might have to click 2 buttons in some scenarios, both which would stop the clock on their own, yet only one button might be needed in other scenarios. Thanks

Something like this, but this doesn't work,

Public Sub StopClock()
If Application.OnTime earliesttime:=NextTick, procedure:="TickTock",schedule:= True Then
Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False
Else
Do nothing
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,821
Messages
6,127,059
Members
449,356
Latest member
tstapleton67

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