We help IT Professionals succeed at work.

How do I pause a macro when a condition is met?

232 Views
Last Modified: 2017-05-05
I have a macro that performs a series of functions on a multitude of tabs. I don't want to stop the macro, I want it to pause it at a specified sheet so I can step through it, and then if it works properly, resume the macro.

Thanks,
John
Comment
Watch Question

Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Quelmo, correct me if I'm wrong but  I believe that Debug.Assert is only recognized while debugging and that doesn't seem to be what the asker wants.
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
The same thing for Stop, and I believe the only way to "pause" a macro is to Exit Sub.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Exit Sub is no pause, it is an exit, leaving the current procedure, without any means to continue execution.
Stop and Debug.Assert are debugging commands, that is correct. But that is what the Asker asked for - a means to execute until a certain code part, than single-step or continue execution. This is debugging, and the debugger is part of VBA.
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Exit Sub is no pause
I know and I realize now that I misread the question, so...

gabriel, the easiest way to pause a macro while debugging is to put a breakpoint at the line where you want it to pause. When you run the coded the macro will pause there. You do that by clicking in the left-hand margin of the line. You may also be interested in this article I wrote on debugging.
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Roy CoxGroup Finance Manager
CERTIFIED EXPERT

Commented:
Exit Sun will stop the macro

End will also do the same but will clear any Global variables.
Protect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions