+ Reply to Thread
Results 1 to 3 of 3

Call Sub for sheet selection - continues onto next lines of code even if you cancel

  1. #1
    Registered User
    Join Date
    03-01-2016
    Location
    Phoenix, AZ
    MS-Off Ver
    MS Office 2013
    Posts
    94

    Question Call Sub for sheet selection - continues onto next lines of code even if you cancel

    I am hoping someone can help me here. I have the following code below I took from a fellow on MrExcel. I call this out to allow the user to select what sheet they would like to use the code on. However, I noticed if I press "Cancel" it continues to run the rest of the code that it is is called out in (highlighted in orange). Is there something I can do so that if "Cancel" is pressed it will actually exit the Sub and stop?



    Select Sheet code:

    Please Login or Register  to view this content.
    Code that calls out the Select Sheet code:

    Please Login or Register  to view this content.
    Attached Images Attached Images

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Call Sub for sheet selection - continues onto next lines of code even if you cancel

    Change the commented line to
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    03-01-2016
    Location
    Phoenix, AZ
    MS-Off Ver
    MS Office 2013
    Posts
    94

    Re: Call Sub for sheet selection - continues onto next lines of code even if you cancel

    Quote Originally Posted by mikerickson View Post
    Change the commented line to
    Please Login or Register  to view this content.
    That didn't work - the thing is I don't think anything needs to be changed in the Sheet_Selector code at all. The problem is that the code continues to run AFTER "Call Sheet_Selector" even if you press the cancel button. The Sheet_Selector code may be exiting the Sub, but it is not existing the Sub that it is called out in...so it continues to run - you will see the enxt lines of code copy the sheet over into the workbook and begins to format it...I don't want it to do anything if the cancel button is pressed!

    I guess what I am trying to say is that I think something needs to be palced in the second code after "Call Sheet_Selector" so that it ends the Sub IF the cancel button is pressed...but I have no idea how you would do this.
    Last edited by CC268; 02-03-2017 at 05:37 PM.

+ 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. [SOLVED] Code works great...UNTIL i call it from another sheet- Why?
    By Ppessina in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-27-2013, 03:52 PM
  2. code not working If i call from a nother sheet?
    By Ppessina in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2013, 12:06 PM
  3. VBA code continues to return to specific cell after data is entered
    By celialynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2012, 08:36 PM
  4. Replies: 2
    Last Post: 10-09-2012, 04:40 PM
  5. Calling the same userform, continues to run through after the "call"
    By gryffin13 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2012, 05:29 PM
  6. Replies: 4
    Last Post: 06-28-2012, 12:42 AM
  7. Replies: 1
    Last Post: 04-13-2011, 09:30 PM
  8. Code causes Error 1004 then continues
    By davegugg in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-09-2009, 03:29 PM

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