+ Reply to Thread
Results 1 to 4 of 4

How to exit all subs when "cancel" is clicked in a vbyesnocancel dialog box

  1. #1
    Registered User
    Join Date
    11-24-2019
    Location
    Malaysia
    MS-Off Ver
    10
    Posts
    1

    How to exit all subs when "cancel" is clicked in a vbyesnocancel dialog box

    Hi there,

    I have a Master Macro which calls on a few sub macros as per below:

    Please Login or Register  to view this content.
    My problem is, whenever user select "cancel" in the dialogbox, the macro will continue running Part2, Part3 and Part4. How can I amend the code such that when user click cancel in Part1, it will exit the macro entirely?
    Last edited by Pepe Le Mokko; 11-24-2019 at 05:42 AM.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: How to exit all subs when "cancel" is clicked in a vbyesnocancel dialog box

    .
    Rather than place this :

    Please Login or Register  to view this content.
    all in one sub .... can you break each one out to a separate sub that follows some logic ?

    Example :

    Leave the first call to CI_Part1

    Then at the bottom of CI_Part1, give the user the opportunity to select the other macro / s ?
    Do this for each of the remaining calls.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: How to exit all subs when "cancel" is clicked in a vbyesnocancel dialog box

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I did it for you this time. Please read forum rules. Thanks

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: How to exit all subs when "cancel" is clicked in a vbyesnocancel dialog box

    Why not just make your CI_Part1 subroutine your MasterMacro_CI subroutine (since, in essence, it is the master code) and call the other subroutines from within it if the user answers Yes to your question? That way, your code will naturally end when there is no code to execute for the Cancel answer. By the way, you can remove this line of code...

    ElseIf OutPut = vbCancel Then

    as the If and ElseIf for vbYes and vbNo handled all the other possibilities.
    Last edited by Rick Rothstein; 11-24-2019 at 05:54 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. vbYesNoCancel - Continue Editing Excel Workbook. WorkSheet after select "Cancel" I'm Stuck
    By Omkar Balgobin in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-18-2017, 12:23 PM
  2. [SOLVED] Exit Sub when Cancel is clicked on Input Box
    By rtcwlomax in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2015, 01:57 PM
  3. [SOLVED] If cancel button is clicked then exit sub problem!?
    By jeroenft in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2014, 08:34 AM
  4. [SOLVED] Code to stop macro when "cancel" is clicked on
    By Devianey26 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2013, 01:57 PM
  5. [SOLVED] user formm cancel button to exit multiple running subs
    By vijaysharmapc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2013, 02:55 PM
  6. Userform cancel button - how to exit multiple subs
    By sotiris5000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-16-2010, 09:56 AM
  7. How to exit a series of subs if cancel is pressed
    By SOS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-05-2008, 04:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1