A Macro To Stop a Running Macro?

ZAX

Well-known Member
Joined
Jul 5, 2012
Messages
715
Hello Everyone,
I Have The Following Macros To Start A Timer In Range A1 And they Work perfectly But The Problem Is That they NEVER Stop no matter what I do even if I removed The First code from the Model or if I pressed Esc; The Only way to stop it is to close the whole program 'Excel',The First Macro is Assigned to a Command Button On The Spreadsheet so I need a Macro Called "Stop_Timer" To Assign it to The Second Command Button To Stop The First Macro "Start_Macro"!
I Hope I'm Clear Enough And I Really Appreciate Your Help. :biggrin:
ZAX
Code:
Sub Start_Timer()
i = 0
Do
i = i + 1
Application.OnTime DateAdd("s", i, Now), "Add"
Loop
End Sub

Sub Add()
Range("a1").Value = Range("a1").Value + 1
End Sub
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Run this to stop the process:


Code:
Sub StopTimer()    
On Error Resume Next    
Application.OnTime EarliestTime:=RunWhen,Procedure:="Add", _
        Schedule:=False
End Sub
 
Upvote 0
Thanks For Your Help But Frankly, The Code Does Nothing At All. Mabe The Problem Is In My Code! If You Can Give Me Another One That Does The Same I'd Be Pleased. :rolleyes:
 
Upvote 0
My error:

Code:
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=Now + TimeSerial(0, 0, 10), Procedure:="Add", _
    Schedule:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,207,205
Messages
6,077,045
Members
446,252
Latest member
vettaforza

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