Exiting a called procedure

  • Thread starter Thread starter rob nobel
  • Start date Start date
R

rob nobel

I have this code....
Sub BalanceFirst()
Call BalanceMessage
Call SortForBalancing
Call First
End Sub
Is there a way to have the BalanceFirst procedure finish completely, if the
VBNo button is press within the BalanceMessage sub. At the moment, all I
can get it to do is exit the BalanceMessage sub, but then it still
progresses to the SortForBalancing sub and so on.

Rob
 
Rob,

I think you mean that there's a message box or input box in BalanceMessage,
and if the user clicks No, then you don't want the sub to finish, but to
exit right there. If that is the case, then there must be a way to test for
that condition, like setting a module-level variable.

Dim UserCancel ' module-level variable. This is before any subs

Sub BalanceFirst()
Call BalanceMessage
If UserCancel = vbNo Then Exit Sub
Call SortForBalancing
Call First
End Sub

Sub BalanceMessage()
UserCancel = MsgBox("Do you want to continue?", vbYesNo)
End Sub
 
Hi Earl. You're summize was correct and thanks for the procedure.
After sending the question, I found some info on the problem and discovered
that puting "Public Response As String" as the first bit of code in the
sheet's module and have "If Response = vbNo Then Exit Sub" within the
procedure , that it does what I need it to do.
Being a bit of a novice, I just try things until they work but can
appreciate that it may not be the best way.
So, could you advise me if what you suggested is just an alternative or a
better way?
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top