+ Reply to Thread
Results 1 to 6 of 6

Exit Sub on InputBox Cancel

  1. #1
    Registered User
    Join Date
    12-06-2014
    Location
    Arizona
    MS-Off Ver
    2011
    Posts
    20

    Exit Sub on InputBox Cancel

    So it seems like this should be simple beyond belief, but regrettably excel doesn't agree, and multiple online searches have failed to produce solutions that work. I have two tables that I need to add and remove names from by pushing corresponding buttons, which bring up a prompt for the name to be entered in. If the user pushes 'Cancel', I just need the macro to exit. My If statement works if the user inputs and empty string, but if they push cancel it populates a 'False' cell to the table, instead of exiting.

    I have tried such code as:

    Please Login or Register  to view this content.
    But the ElseIf statement fails due to type mismatch. Here is my code for adding to the table as it stands:

    Please Login or Register  to view this content.
    All help is greatly appreciated.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    2007
    Posts
    3,234

    Re: Exit Sub on InputBox Cancel

    Hi there,

    Try replacing this line of code...

    Please Login or Register  to view this content.
    ...with this:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,866

    Re: Exit Sub on InputBox Cancel

    Good evening qwerty7

    Use this line to handle the cancelling bit :
    Please Login or Register  to view this content.
    HTH

    DominicB

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    I design and/or assist on projects used across multiple countries. If it's region specific, please ask instead of assuming.
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Exit Sub on InputBox Cancel

    Try

    Please Login or Register  to view this content.
    HTH
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  5. #5
    Registered User
    Join Date
    12-06-2014
    Location
    Arizona
    MS-Off Ver
    2011
    Posts
    20

    Re: Exit Sub on InputBox Cancel

    It actually turned out to be the "False" in quotes that solved it, which I find curious becuase it seems like the False that excel automatically populates should be a boolean, not a string. False without the quotes gave me an error, not sure why....

    Thank you all much for the help though.

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    I design and/or assist on projects used across multiple countries. If it's region specific, please ask instead of assuming.
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Exit Sub on InputBox Cancel

    Quote Originally Posted by qwerty7 View Post
    False without the quotes gave me an error, not sure why....
    Maybe - you were comparing it to variable newName which is a string. Without the quotes you were comparing a string to a boolean value. With the quotes you were comparing two strings.

+ 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] If Cancel on Input Box, exit sub
    By guitarsweety in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-28-2014, 07:24 PM
  2. [SOLVED] Input Box - Exit Sub on Cancel
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2013, 11:32 AM
  3. tidy way to exit sub on cancel
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2009, 04:44 AM
  4. Exit Sub when I hit cancel
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2007, 01:27 PM
  5. Cancel an application exit from VBA?
    By helmekki in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2005, 10:31 PM

Tags for this Thread

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