Avatar of John Carney
John Carney
Flag for United States of America asked on

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

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
Microsoft OfficeMicrosoft ExcelVBA

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
SOLUTION
Subodh Tiwari (Neeraj)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Martin Liss

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 Liss

The same thing for Stop, and I believe the only way to "pause" a macro is to Exit Sub.
Qlemo

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Martin Liss

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.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Roy Cox

Exit Sun will stop the macro

End will also do the same but will clear any Global variables.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.