Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Kill Macro
Hi,
I am running a macro and want to put in an option where the program stops under certain conditions IF (statement=true) then stop the macro I was using "Exit Sub" but this just kicks it out of the sub(), not the entire macro. Is there a way to end the entire macro? Thanks for your help! |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Kill Macro
Instead of Exit Sub, use End
IF (statement=true) then stop the macro "Jeff" wrote in message ... Hi, I am running a macro and want to put in an option where the program stops under certain conditions IF (statement=true) then stop the macro I was using "Exit Sub" but this just kicks it out of the sub(), not the entire macro. Is there a way to end the entire macro? Thanks for your help! |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Kill Macro
You do this with the statement End. That's it. It is highly recommended,
though, that you not ever use the End statement. You will be taking a chance of leaving a lot of loose ends. Don't do it!!!! You can back out of all the code in an orderly fashion. I do it all the time. Post back and provide more detail about what you have. For instance, what is the condition that will provoke you to end all code running? HTH Otto "Jeff" wrote in message ... Hi, I am running a macro and want to put in an option where the program stops under certain conditions IF (statement=true) then stop the macro I was using "Exit Sub" but this just kicks it out of the sub(), not the entire macro. Is there a way to end the entire macro? Thanks for your help! |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Kill Macro
You could use a global variable which is initially set to False, but
gets set to True by your statement (as well as Exit Sub there). Then in all your subs you could check for the variable being True at the start and Exit Sub if it is. Hope this helps. Pete Jeff wrote: Hi, I am running a macro and want to put in an option where the program stops under certain conditions IF (statement=true) then stop the macro I was using "Exit Sub" but this just kicks it out of the sub(), not the entire macro. Is there a way to end the entire macro? Thanks for your help! |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Kill Macro
Jeff
For instance, let's say you have a macro like this: Sub Macro Call Macro2 Call Macro3 End Sub And you want to place your IF statement in Macro2 and stop all code if True. Do something like this: Dim CancelA As Boolean Sub Macro CancelA = False Call Macro2 If CancelA = True Then Exit Sub Call Macro3 End Sub Within Macro2 you would have: If (Statement = True) Then CancelA = True Exit Sub End If HTH Otto "Jeff" wrote in message ... Hi, I am running a macro and want to put in an option where the program stops under certain conditions IF (statement=true) then stop the macro I was using "Exit Sub" but this just kicks it out of the sub(), not the entire macro. Is there a way to end the entire macro? Thanks for your help! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
error when running cut & paste macro | Excel Worksheet Functions | |||
Compiling macro based on cell values | Excel Discussion (Misc queries) | |||
Search, Copy, Paste Macro in Excel | Excel Worksheet Functions | |||
Closing File Error | Excel Discussion (Misc queries) | |||
Highlight Range - wrong macro, please edit. | Excel Worksheet Functions |