Exit Sub Macro Help

EricL89

New Member
Joined
May 29, 2014
Messages
34
Kind of new to macros and VBA, but I'm starting to get the hang of it. I'm currently using Excel 2007.

My document has one module, and the main sub runs three other subs. i.e.:

Sub Master()

MiniSub1
MiniSub2
MiniSub3

End Sub



In the sub I'm calling MiniSub1, I have a MsgBox which I'm using vbOKCancel. With that, I have:

Dim ErrorMessage As String

ErrorMessage = MsgBox("You messed up",vbOKCancel)

If ErrorMessage = vbOK Then

***(some code here)***

Else
Exit Sub
End If
***(followed by a lot more code)***

The Exit Sub and the code as a whole work great, but I'd like it to exit the entire sub (Master); just stop everything there and end the macro. Instead, after clicking "cancel" the macro proceeds to MiniSub2.

This is intended to be similar to an error message, where clicking "Ok" lets you continue, while clicking "Cancel" lets you stop everything to fix the error before running it again.

I'd expect it'd be some code inserted in Sub Master(), but I have no idea what to do.

Is this possible? And if so, thanks for your help!

Eric
 
Nope, I jumped the gun; this statement doesn't completely work. I changed vbOKCancel to VBYesNo, and reworded the message a little bit, but that doesn't affect it, just made the message box easier to understand. Regardless, clicking "Yes" tells the macro to continue running as normal, whereas clicking "No" ends EditMaster and goes back to the main sub. At this point, the "Then Exit Sub" comes into play and ends the macro as desired. All of that works great, but the problem is with clicking "Yes".

Even though clicking "Yes" does allow the macro to continue, as soon as the macro gets to the end of "Do Until" the main sub goes to the "Then Exit Sub" instead of moving on to EditSold.

Any thoughts on how to resolve this issue, Rick?
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

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