+ Reply to Thread
Results 1 to 4 of 4

Are there drawbacks to using the "End" statement?

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    77

    Are there drawbacks to using the "End" statement?

    A while ago when I was trying to figure out how to end a macro completely if something goes wrong in a sub that was called by another main sub, I ended up finding the End statement. It seemed like the cleanest way to stop everything, without having to put an exit sub statement in both subs. Today I was on the MSDN help page for the end statement and it suggests using it sparingly. I haven't run into any trouble so far and it seems like a relatively simple statement. Going forward I may instead start raising user defined errors to stop the process instead.

    Does anyone have an opinion on this?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Are there drawbacks to using the "End" statement?

    Yes, use it sparingly.
    As it says it will reset all public variables. Whilst this may not directly impact your coding it may affect code in any addins you use.

    Have a read of the help on End witin VBA.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    07-10-2013
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    77

    Re: Are there drawbacks to using the "End" statement?

    Quote Originally Posted by Andy Pope View Post
    Yes, use it sparingly.
    As it says it will reset all public variables. Whilst this may not directly impact your coding it may affect code in any addins you use.

    Have a read of the help on End witin VBA.
    Thank you. Let's say I instead raise a user error. If the user hits "End" instead of "Debug" when the dialog box comes up, do you know if this would also reset all public variables?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Are there drawbacks to using the "End" statement?

    Yes it would.

    why not handle the error(s). you can capture it and report information if relevant without relying on the end/debug dialog.

+ 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 Statement Evaluates as "TRUE" but Returns "FALSE" Value (Excel 2007)
    By Simcik in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-11-2014, 12:43 PM
  2. How do I do incorporate an "if statement" with the ".find" method in a range?
    By max3732 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2014, 08:14 PM
  3. Replies: 12
    Last Post: 06-12-2014, 02:11 PM
  4. Replies: 2
    Last Post: 05-17-2012, 03:12 AM
  5. Replies: 3
    Last Post: 12-14-2006, 01:36 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