How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Richard Your Own Question
Richard, Software Specialist
Category: Microsoft Office
Satisfied Customers: 36820
Experience:  Over 15 year experience resolving Microsoft Office Issues
Type Your Microsoft Office Question Here...
Richard is online now
A new question is answered every 9 seconds

I have an Excel 2010 VBA procedure which runs every 6 seconds.

This answer was rated:

I have an Excel 2010 VBA procedure which runs every 6 seconds. After a certain time I start a second procedure that runs every six seconds. I am using the OnTime capabilities.

Problem: I cannot make the first procedure stop when the VBA switches to the second procedure. I need some sort of halt for the first procedure. If I use STOP the entire program stops.

Thanks. Palmer.
Thank you for your question, my name is Richard.

That is correct, it will stop all of the procedures.

What you will want to do is use a Global Variable.

For instance, at the top of the Code sheet (right at the very top) you set

Public Switch As String

then in your first procedure, you have an if statement

if Switch = "True" then exit sub

Then in your second procedure, when you want to stop the first procedure, you set Switch to try

Switch = "True"

This is how you would turn off the procedure.

If you have any difficulties at all, please do not hesitate to let me know so I can assist you further

Thank you

Richard and 2 other Microsoft Office Specialists are ready to help you
Customer: replied 4 years ago.

Thank you very much for your help. As soon as you gave me the clue of setting a global variable I understood your method. It took me a while to get it working because the program has multiple procedures which call each other in sequence. I also discovered that one can cause branching on certain times simply by the devise of setting of multiple OnTime which call different procedures at later and later times. Thanks again for your speedy response. Palmer.


You are most welcome Palmer, and good to know it is working the way you need it to.

If you need anything else at all, anytime, please do not hesitate to let me know.

Thank you


Related Microsoft Office Questions