Basic VBA question

  • Thread starter Thread starter paolo
  • Start date Start date
P

paolo

Is this a good idea?

Sub blahblah
On error goto Error

If blahblahblah then
Return:
(code stuff here)
End If

Blahblah:
Exit Sub

Error:
If blahblahblah then
Goto Return
End If

Resume Blahblah
End Sub

In other words is a goto statement to the middle of an if then
statement inherently a bad idea?

Thanks in advance,
Paolo
 
In error trapping, it makes far more sense to use Resume Return rather than
GoTo Return, as Resume will clear the error buffer as well as transfer
program control.

I'd also question returning control to within an If construct, suggesting
you return to before the If statement instead, just in case you shouldn't be
executing the code.

Return:
If blahblahblah then
(code stuff here)
End If
 
Back
Top