Exit a running procedure from the Called proceduer

abi_learn_vba

Board Regular
Joined
Nov 6, 2009
Messages
215
Hi,

I am running a procedure called as "Sub Report" which Calls another procedure and based on checking some condition in that i need stop all my running procedure. Can this be done? Within Same procedure i can use Exit Sub. But from another procedure.

Code:
Sub Report()

Call nwprocedure

End Sub

Sub nwprocedure

'on some condition
'need to exit all the procedure including "Sub report"

End Sub


Thanks
-Abi
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
There are a couple of ways, one would be to replace the subordinate Sub with a Function

Code:
Sub Main()
    Rem do stuff

    If SubordinateRoutine() = False Then Exit Sub

    Rem do the rest
End Sub

Function SubordinateRoutine() As Boolean
    Rem do something

    If BadThing then
        SubordinateRoutine = False
    Else
        SubordinateRoutine = True
    End If

End Function
The other methods would be very similar, just using global variables or a variable passed to SubordinateRoutine byRef.
 
Upvote 0
You can also use End, but that will stop all code execution.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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