Stepping Through Code With Unexpected Exit From Procedure

Ark68

Well-known Member
Joined
Apr 5, 2005
Messages
3,187
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.
 

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,143
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.
 

Ark68

Well-known Member
Joined
Apr 5, 2005
Messages
3,187
Thanks Jeff ...

Rich (BB 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:

Ark68

Well-known Member
Joined
Apr 5, 2005
Messages
3,187
OK, if this is OK ... I think I resolved the problem.
Added the line in green ..

Rich (BB 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
 

Ark68

Well-known Member
Joined
Apr 5, 2005
Messages
3,187
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.
 

Forum statistics

Threads
1,078,252
Messages
5,339,097
Members
399,277
Latest member
Jyoti C

Some videos you may like

This Week's Hot Topics

Top