exiting a sub within a sub

tealeaf

Board Regular
Joined
May 15, 2002
Messages
160
hey
i have a module which calls another one. let's say
Sub A()
call B
end sub

sub B()
exit sub
end sub

i want to be able to exit both B and A sub. is that possible?

thanks in advance
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
With the subs you have listed, sub A will run and close and so will sub B. If you have a UserForm that is called up within sub A, I believe it will still be showing until sub B is done. If your specific issue is having the UserForm disappear, you may want to use an Unload UserForm command just before the Call statement.

Did this help?
 

tealeaf

Board Regular
Joined
May 15, 2002
Messages
160
hi thanks!
in fact there is code in sub A after the call of sub B so it's more like:
sub A()
call B
....(code)....
end sub
sub B
...(code)...
exit sub
end sub

i don't want the code after the call B to be executed.
is that possible?
 

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
The mystery is why you would even write code after the Call B in Sub A. You will probably need to qualify your code within Sub A so that the code knows whether to Call Sub B or to continue with Sub A. You will probably want to do something like this:

If (WHATEVER YOUR CONDITION IS) Then
Call Sub B
Exit Sub
End If

Does that help?
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329

ADVERTISEMENT

Hi Tealeaf,

How about passing a variable from Sub B to Sub A (obviously placed before the Exit Sub line!) and then using an If..Then test in Sub A such that if the variable is True then Exit Sub?

Eg Dim fCloseTest as Boolean (Module level variable)

Then in Sub B use fCloseTest=True and,
in Sub A If fCloseTest=True Then Exit Sub
(set the variable to False at the start of Sub A).

Would this work for you?
 

tealeaf

Board Regular
Joined
May 15, 2002
Messages
160
On 2002-08-29 08:35, Juan Pablo G. wrote:
The drastic solution would be to use End instead of Exit Sub

in fact this is the solution to my problem
i just want to thank everyone who helped. i chose the less elegant solution i think...but it works and it's fast. so i'm glad.
thanks again
 

Forum statistics

Threads
1,147,677
Messages
5,742,566
Members
423,738
Latest member
AshleyKitsune

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top