Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Stepping Through Code With Unexpected Exit From Procedure

  1. #1
    Board Regular
    Join Date
    Apr 2005
    Location
    Ontario, Canada
    Posts
    2,942
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Stepping Through Code With Unexpected Exit From Procedure

    I'm discovering an odd problem ...

    As I am stepping through my code, when I reach a particular line in a procedure, it suddenly jumps out of the procedure and goes back to the 'next' of the loop from which that procedure was called.

    I am inclined to think that if there is an error with the line, it leaves the procedure.

    I am relatively new to Excel VBA, so I can't begin to imagine why this behaviour exists. Could it have something to do with "on error resume next"? code? I don't use it very often (only a small handful of instances in my project) I know I don't have it in the procedure that is being exited, so unsure how, if at all, this may be part f it.

    Any help would be greatly appreciated.

  2. #2
    Board Regular jeffreybrown's Avatar
    Join Date
    Jul 2004
    Posts
    5,140
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Stepping Through Code With Unexpected Exit From Procedure

    Quote Originally Posted by Ark68 View Post
    Could it have something to do with "on error resume next"?
    I would be inclined to say yes. The "on error resume next" is hiding the error.

    REM out that line so you can see the real error.
    Jeff

  3. #3
    Board Regular
    Join Date
    Apr 2005
    Location
    Ontario, Canada
    Posts
    2,942
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Stepping Through Code With Unexpected Exit From Procedure

    Thanks Jeff ...

    Code:
                    'On Error Resume Next 'bypasses error created by accessing header row for 1st comparison
                    pp_start = .Range("N" & i - 1)
    This was the only instance of ON ERROR in the module. With it removed, I am receiving a 'Type Mismatch' error, but I'm not being directed to where. (shouldn't the erroneous line be highlighted?)

    I will take a stab at saying its the line in blue, as without the preceeding 'on error' line, it is encountering an error. pp_start is declared as double, but with this line if it access n-1, which could be the header row of the data, it will encounter text and throw an error. The On Error line was put in to bypass this in this scenario.

    So, what would an option be to overcome this?
    Last edited by Ark68; Mar 25th, 2016 at 02:50 PM.

  4. #4
    Board Regular
    Join Date
    Apr 2005
    Location
    Ontario, Canada
    Posts
    2,942
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Stepping Through Code With Unexpected Exit From Procedure

    OK, if this is OK ... I think I resolved the problem.
    Added the line in green ..

    Code:
        On Error Resume Next 'bypasses error created by accessing header row for 1st comparison
            pp_start = .Range("N" & i - 1)
        On error goto 0

  5. #5
    Board Regular jeffreybrown's Avatar
    Join Date
    Jul 2004
    Posts
    5,140
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Stepping Through Code With Unexpected Exit From Procedure

    Glad to see you have a working solution.

    Maybe this is worth taking a look at On Error WTF? | Excel Matters
    Jeff

  6. #6
    Board Regular
    Join Date
    Apr 2005
    Location
    Ontario, Canada
    Posts
    2,942
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Stepping Through Code With Unexpected Exit From Procedure

    Thanks for the good read Jeff. Not too technical so easy to digest. I've added that to my collection of good resources for the future.

  7. #7
    Board Regular jeffreybrown's Avatar
    Join Date
    Jul 2004
    Posts
    5,140
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Stepping Through Code With Unexpected Exit From Procedure

    Jeff

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •