Cannot Stop my Time-Counter

Telefonstolpe

Board Regular
Joined
Sep 25, 2014
Messages
55
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:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
.
.

Try this syntax instead:

Code:
Sub StopTimer()

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

End Sub
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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