Stepping Through Code With Unexpected Exit From Procedure

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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:
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top