Cannot Stop my Time-Counter

Telefonstolpe

Board Regular
Joined
Sep 25, 2014
Messages
53
Hi,

I've got a macro that, when activated, counts the time in seconds in cell F2, starting on zero.
That macro works perfectly well.

However it's the third Macro "StopTimer" that doesn't work and I cannot figure out why.
Error Message: "Run-time error '1004': Method 'OnTime of object '_Application' failed"

Sub StartTimer()
Application.OnTime Now + TimeValue("00:00:01"), "Increment_count"
End Sub


Sub Increment_count()
Range("F2").Value = Range("F2") + 1
StartTimer
End Sub


Sub StopTimer()
Application.OnTime Now + TimeValue("00:00:01"), "Increment_count", Schedule:=False
End Sub


Is there somebody who can see what I have don wrong?

Regards /Chris
 
Last edited:

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

ParamRay

Well-known Member
Joined
Aug 6, 2014
Messages
1,195
.
.

Try this syntax instead:

Code:
Sub StopTimer()

    Application.OnTime _
        EarliestTime:=Now + TimeValue("00:00:01"), _
        Procedure:="Increment_count", _
        Schedule:=False

End Sub
 

Telefonstolpe

Board Regular
Joined
Sep 25, 2014
Messages
53
Hi and thanks for your time,

Unfortunately it didn't work, it resulted in the same error-message as before.

However I discovered that the time-counting macro wasn't working as well as I thought:
It stops counting as soon as you start editing in the worksheet, which is not desireable,
so I have to change the whole code...

/Chris
 

Watch MrExcel Video

Forum statistics

Threads
1,122,955
Messages
5,599,040
Members
414,280
Latest member
morralletti

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
Top