Link to home
Create AccountLog in
Avatar of John Carney
John CarneyFlag 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
SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.
The same thing for Stop, and I believe the only way to "pause" a macro is to Exit Sub.
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.
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
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Exit Sun will stop the macro

End will also do the same but will clear any Global variables.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account