Moidule Line # continued

D

Don Cossitt

OK. Alex and Geof were very helpful - thanks. However, the next logical
step would then be able to 'GoTo' Erl. To simply code GoTo Erl produces an
missing label error.

This is not critical but, how then would one have a jump to that line after
anouncing it's presence? Again, just curious.

TIA
doco
 
T

Trevor Shuttleworth

Don

something like:

Sub Test()
' code
GoTo ErrL
' code
MsgBox "don't get here"
' code
ErrL:
MsgBox "but do get here"
End Sub

Note the colon after the label


Regards

Trevor
 
D

Don Cossitt

Yes I understand how to label a line. But if, in this case I desire to
'GoTo' a line number - not labeled.

Eg.

Public Sub TestError()
Dim lErr As Long
10 On Error GoTo EH

20 lErr = 1 / 0

30 On Error GoTo 0
40 Exit Sub

EH:

50 MsgBox "Error " & err.Number & vbCr & _
err.Description & " in line " & Erl, vbInformation,
"TestError"

GoTo Erl ' this part... how would one jump to the
offending line? Again, just curious - probably wouldn't do it actually.

End Sub
 
C

Chip Pearson

Don,

Never use Goto in an error handling block of code. Instead, use
Resume to go to the line that cause the error, or Resume Next to
go to the line following the line that caused the error.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top