ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Exit Sub (https://www.excelbanter.com/excel-programming/362221-exit-sub.html)

Raman325[_38_]

Exit Sub
 

I have a subroutine which calls another subroutine. The child subroutine
has an error mechanism that displays a message and then is supposed to
exit out of the subroutine. Exit Sub only works for the child
subroutine, however, and the main subroutine which called the child
subroutine still runs. Is there a call or command to exit out of
everything? Thanks in advance.


--
Raman325
------------------------------------------------------------------------
Raman325's Profile: http://www.excelforum.com/member.php...o&userid=24748
View this thread: http://www.excelforum.com/showthread...hreadid=544854


Jim Rech

Exit Sub
 
You can use the End statement. Be aware that it clears all variables as
well as ending code execution.

--
Jim
"Raman325" wrote in
message ...
|
| I have a subroutine which calls another subroutine. The child subroutine
| has an error mechanism that displays a message and then is supposed to
| exit out of the subroutine. Exit Sub only works for the child
| subroutine, however, and the main subroutine which called the child
| subroutine still runs. Is there a call or command to exit out of
| everything? Thanks in advance.
|
|
| --
| Raman325
| ------------------------------------------------------------------------
| Raman325's Profile:
http://www.excelforum.com/member.php...o&userid=24748
| View this thread: http://www.excelforum.com/showthread...hreadid=544854
|



Michael

Exit Sub
 
Yes: Exit Sub

"Raman325" wrote:


I have a subroutine which calls another subroutine. The child subroutine
has an error mechanism that displays a message and then is supposed to
exit out of the subroutine. Exit Sub only works for the child
subroutine, however, and the main subroutine which called the child
subroutine still runs. Is there a call or command to exit out of
everything? Thanks in advance.


--
Raman325
------------------------------------------------------------------------
Raman325's Profile: http://www.excelforum.com/member.php...o&userid=24748
View this thread: http://www.excelforum.com/showthread...hreadid=544854



Dave Peterson

Exit Sub
 
A couple of common techniques a

1. Use a global boolean variable and set that in each subroutine. Then you can
examine that to see if you should quit or continue.

2. Another way would be to change your child subroutines to functions. Let
them return a boolean variable that you can check.



Raman325 wrote:

I have a subroutine which calls another subroutine. The child subroutine
has an error mechanism that displays a message and then is supposed to
exit out of the subroutine. Exit Sub only works for the child
subroutine, however, and the main subroutine which called the child
subroutine still runs. Is there a call or command to exit out of
everything? Thanks in advance.

--
Raman325
------------------------------------------------------------------------
Raman325's Profile: http://www.excelforum.com/member.php...o&userid=24748
View this thread: http://www.excelforum.com/showthread...hreadid=544854


--

Dave Peterson

Raman325[_39_]

Exit Sub
 

Thank you for all the responses, that helps a lot.


--
Raman325
------------------------------------------------------------------------
Raman325's Profile: http://www.excelforum.com/member.php...o&userid=24748
View this thread: http://www.excelforum.com/showthread...hreadid=544854



All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com