Stopwatch on a userform.

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Good Day,
Is it possible to place on a userform one stopwatch for 3min?
It will stop when it is 00:00
it will start when double click on userformom 03:00:60
Thanks in advance.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,

In userform paste this code:
VBA Code:
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  alertTime = Now + TimeValue("00:00:01")
  Application.OnTime alertTime, "tictoc"
End Sub
Private Sub UserForm_Initialize()
  initialtime = TimeValue("00:03:00")
  Label1.Caption = Format(initialtime, "hh:nn:ss")
End Sub
Then create a standard module and paste this:
VBA Code:
Public initialtime As Double
Sub tictoc()
  initialtime = initialtime - TimeValue("00:00:01")
  UserForm1.Label1.Caption = Format(initialtime, "hh:nn:ss")
  alertTime = Now + TimeValue("00:00:01")
  If initialtime > 1 / 86400 Then
    Application.OnTime alertTime, "tictoc"
  End If
End Sub
 
Upvote 0
Solution
Thank you so much.
How do we reset the code in the middle of progress?
 
Upvote 0
I think you will need something like this. Make a Reset button. Modify the useerform code like this
VBA Code:
Private Sub Reset_Click()
  Call resetTime
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  alertTime = Now + TimeValue("00:00:01")
  Application.OnTime alertTime, "tictoc"
End Sub
Private Sub UserForm_Initialize()
  Call resetTime
End Sub
Private Sub resetTime()
  initialtime = TimeValue("00:03:00")
  Label1.Caption = Format(initialtime, "hh:nn:ss")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,137
Messages
6,123,254
Members
449,093
Latest member
Vincent Khandagale

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