how to stop the parent sub when a child (i.e. called) sub stops in the middle

lindalibinbin

New Member
Joined
Dec 23, 2013
Messages
6
I have a procedure that looks like this:

sub parent()

call child1

call child2

end sub


My question is, since child1 grabs the correct files, and child2 processes the new files, when child1 stops (i.e. feed file not ready to be grabbed), the whole thing should stop right there. But when I ran it, it will still continue onto child2, which in turn wastes time processing OLD data. So how do I tell the parent sub to stop if child1 cannot run all the way to its end?

Thanks!!
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
sounds like you need to throw in an error handler to basically say, if file reaches X then Exit Sub.
This could be placed in each of your subs :)

without seeing the code or more detail thats the best i can think of.

Regards
 
Upvote 0
Three ways I can think of:
1. Change your subs to Functions that return True if they succeed, or False if not. The calling code can then simply check the result:
Code:
sub parent()

If child1 = False then Exit sub

Call child2

end sub

2. Use an error handler in your calling sub and raise an unhandled error in the called sub - this will come back up the stack to the parent.
3. Use End. This should be a last resort!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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
Back
Top