+ Reply to Thread
Results 1 to 6 of 6

Runtime Error 91 when Macro canceled

  1. #1
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Runtime Error 91 when Macro canceled

    I have the following macro that works fine when the requested Input is supplied.

    However, if you hit "Cancel" or just don't input anything, an error message is displayed along with the Message Box stating that "No Recipe # Chosen":
    "Run-time error '91': Object variable or With block variable not set"

    I want the macro to stop if no Input is given or if the user hits Cancel. What can I add or change to make this happen?

    Here's the code:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,126

    Re: Runtime Error 91 when Macro canceled

    Add this line
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,629

    Re: Runtime Error 91 when Macro canceled

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Runtime Error 91 when Macro canceled

    Fluff13, Thanks so much! I knew it was something simple. I am a Super Newbie with VBA, obviously.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,126

    Re: Runtime Error 91 when Macro canceled

    Glad to help & thanks for the feedback.

    You also might want to take into consideration the modification suggested by protonleah.
    Whilst your code will work it's not the "normal" way of writing it.

  6. #6
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Runtime Error 91 when Macro canceled

    Quote Originally Posted by Fluff13 View Post
    Glad to help & thanks for the feedback.

    You also might want to take into consideration the modification suggested by protonleah.
    Whilst your code will work it's not the "normal" way of writing it.
    Thanks! I went in a revised to use both methods I rearranged the syntax and left the NOT out of the other method and kept your Exit Sub. I don't know why I did that, it just made more sense to me. Either way, it works the way I wanted it to.

    I appreciate the help and the extra explanation.

+ 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. 'This operation has been canceled' new Excel error
    By Compusafe in forum Excel General
    Replies: 1
    Last Post: 09-09-2017, 04:20 PM
  2. [SOLVED] runtime error on macro in vba
    By murray83 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2017, 05:59 AM
  3. canceled and restore arrows are grayed out in Excel with this macro
    By gibtoul in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-31-2013, 11:32 AM
  4. Runmacro action was canceled error
    By sai_htwe in forum Access Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2009, 11:55 AM
  5. macro Runtime Error
    By Dave 2005 in forum Excel General
    Replies: 1
    Last Post: 10-18-2005, 05:05 PM
  6. Excel 2003 Macro Error - Runtime error 1004
    By Cow in forum Excel General
    Replies: 2
    Last Post: 06-07-2005, 09:05 AM
  7. naming tab macro error runtime error 1004
    By D in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2005, 10:06 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