+ Reply to Thread
Results 1 to 4 of 4

On Error GoTo not working as expected

  1. #1
    Forum Contributor
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    290

    On Error GoTo not working as expected

    This section of code is causing an error:

    Please Login or Register  to view this content.
    the error is: "No Cells Were Found"

    and that is ok, its what I expect to happen. So If this error happens, I want to redirect the code to the end of the macro but "GoTo EndMacro" isnt doing that for some reason. I have that Label in my script but the code just doesnt want to be redirected to it.

    any1 know why? is there a simple solution?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: On Error GoTo not working as expected

    Please Login or Register  to view this content.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: On Error GoTo not working as expected

    Two possibilities spring to mind:
    1. You have already used on On Error Goto statement somewhere without then using a Resume statement.
    2. You have your VBE set to break on all errors.
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Contributor
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    290

    Re: On Error GoTo not working as expected

    @romperstomper yes I have used an "On Error GoTo" statement somewhere without using "Resume"

    I basically have this sort of set up:

    Please Login or Register  to view this content.
    where would I put the resume? before the "Part2" section?

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: On Error GoTo not working as expected

    What you should do is rewrite and restructure your code! Impossible to be specific with no actual code to go on, but as a general guideline you should have one error handler per routine (if any).

    The fact that you have all those different Goto statements suggests that you should probably be using multiple routines, or at the very least restructuring the code you have now so that it doesn't leap around so much.

    For your specific visiblecells issue here, I would actually use something like:
    Please Login or Register  to view this content.

+ 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] On Error Goto statement not working when looping
    By som3on3_10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 12:58 PM
  2. GoTo compile error: "Expected: line number or label"
    By elfsprin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-29-2011, 09:21 PM
  3. [SOLVED] On Error GoTo Label in a loop only working once.
    By Ken Johnson in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-05-2006, 04:45 PM
  4. [SOLVED] Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM
  5. [SOLVED] Lookup Not working as expected
    By trumpy81 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 06-30-2005, 03:05 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