+ Reply to Thread
Results 1 to 4 of 4

Code to stop macro when "cancel" is clicked on

  1. #1
    Registered User
    Join Date
    11-15-2013
    Location
    U.S.A
    MS-Off Ver
    Excel 2010
    Posts
    24

    Code to stop macro when "cancel" is clicked on

    I have an Excel sheet that shows a column with names. In my Macro I select (via an input box) the name of the person who I want to see. When I enter the name all the data associated with that person and within that row will be displayed. My code works fine, except, when "Cancel" is hit. I need code that will stop the macro when "Cancel" is entered, as of now the macro continues, I need it to stop. Any suggestions? Here is my code:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Code to stop macro when "cancel" is clicked on

    Please Login or Register  to view this content.
    Put this immediately after using the input box to set the ans1 variable.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    11-15-2013
    Location
    U.S.A
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Code to stop macro when "cancel" is clicked on

    Thanks Solus, I can't believe how simple that was. I was thinking too much !

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Code to stop macro when "cancel" is clicked on

    No problem. Glad I could help.

    If you are happy with the solution please mark the thread as [SOLVED] using the thread tools at the top.

+ 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. Stop Macro after cancel is on vbCancel is clicked
    By juliorevka in forum Excel General
    Replies: 5
    Last Post: 03-08-2012, 06:57 PM
  2. Code to say "if the selected cell is within a range and is double clicked"...
    By diputz42 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2010, 10:16 PM
  3. How do I stop a Macro after "Cancel" is chosen in an input box?
    By c991257 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2007, 02:27 PM
  4. [SOLVED] Stop code from running when I click "Cancel"
    By Dean in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2006, 08:40 PM
  5. Replies: 6
    Last Post: 01-08-2006, 06:20 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