#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,311
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,090
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,090
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 07:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Highlight Range - wrong macro, please edit. Danny Excel Worksheet Functions 8 October 19th 05 11:11 PM


All times are GMT +1. The time now is 01:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"