Does Stop in a sub-procedure always persist to the caller?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,676
Office Version
  1. 365
Platform
  1. Windows
If I write a general-purpose error handler that, among other things, executes a Stop statement under certain conditions, can I be assured that it will persist past the termination of the sub-function and allow me to continue stepping through the caller using F8?

I have tested it and it seems to work, but I'd like to hear from anyone who knows for sure that it does or if there are conditions where it does not. The caller and subroutine are in the same module.

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Could you post some code illustrating your scenario? I'm struggling to get my head around your question
 
Upvote 0
Could you post some code illustrating your scenario? I'm struggling to get my head around your question
Sure.

Code:
Public Function MainFn(. . .)
 . . .
If (some error condition) then
  Call ErrorHandler(. . .)
  MainFn = CVErr(xlErrValue): Exit Function
End If
 . . .
End Function


Public Function ErrorHandler(. . .)
. . .
Dim Button as Long
Button = MsgBox(". . .", vbYesNo, . . .)
If Button = vbYes then Stop
 . . .
End Function

The error handler puts up a MsgBox asking the user whether to issue a Stop so some debugging can take place.

My question is, "Will the Stop statement in ErrorHandler still be in effect when it returns control to MainFn? That is, after the Stop interrupts execution, can I step through the code using F8 for the rest of ErrorHandler and back into MainFn?

I've tested it and it seems to work, but VBA is quirky, so I wanted to be sure it would always work and that there is not a better way.

Clearer?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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