Stopwatch macro

wil

New Member
Joined
Oct 18, 2002
Messages
1
Anyone have a stopwatch macro. I would like to present a countdown timer using excel. Want to put in a variable number of minutes or seconds and count down to zero.

Thanks
 
Hey,

Why it doesnt work for me :(

When I run it, it says compile error: Expected end sub.

PLZ HELP



This (Count_Down_Timer) counts down 60 secs to 0 in A1. It also puts a message in B1. Adapt to suit.

Option Explicit
Option Base 1

Dim AlarmTime As Date, AlarmTime2 As Date
Sub Count_Down_Timer()
ActiveSheet.Range("A1").Value = 60
ActiveSheet.Range("B1").Value = "Counting"
Call TrapTime
Call TrapTime2
End Sub
Private Sub ShowTimeLeft()
ActiveSheet.Range("A1").Value = Second(AlarmTime - Now)
Call TrapTime2
End Sub
Private Sub TrapTime()
AlarmTime = CDate(Date) + TimeValue(Now()) + TimeValue("00:01:00")
Application.OnTime earliesttime:=AlarmTime, procedure:="StopTimer"
End Sub
Private Sub TrapTime2()
AlarmTime2 = CDate(Date) + TimeValue(Now()) + TimeValue("00:00:01")
Application.OnTime earliesttime:=AlarmTime2, procedure:="ShowTimeLeft"
End Sub
Private Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=AlarmTime2, procedure:="showtimeleft", schedule:=False
On Error GoTo 0
ActiveSheet.Range("B1").Value = "Done"
End Sub
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This compiles fine for me - make sure that you copy all of the code

Code:
Dim AlarmTime As Date, AlarmTime2 As Date
Sub Count_Down_Timer()
ActiveSheet.Range("A1").Value = 60
ActiveSheet.Range("B1").Value = "Counting"
Call TrapTime
Call TrapTime2
End Sub
Private Sub ShowTimeLeft()
ActiveSheet.Range("A1").Value = Second(AlarmTime - Now)
Call TrapTime2
End Sub
Private Sub TrapTime()
AlarmTime = CDate(Date) + TimeValue(Now()) + TimeValue("00:01:00")
Application.OnTime earliesttime:=AlarmTime, procedure:="StopTimer"
End Sub
Private Sub TrapTime2()
AlarmTime2 = CDate(Date) + TimeValue(Now()) + TimeValue("00:00:01")
Application.OnTime earliesttime:=AlarmTime2, procedure:="ShowTimeLeft"
End Sub
Private Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=AlarmTime2, procedure:="showtimeleft", schedule:=False
On Error GoTo 0
ActiveSheet.Range("B1").Value = "Done"
End Sub

The first line of code has to go at the top of the module before Sub statements.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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