ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moidule Line # continued (https://www.excelbanter.com/excel-programming/313446-moidule-line-continued.html)

Don Cossitt

Moidule Line # continued
 
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



Trevor Shuttleworth

Moidule Line # continued
 
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


"Don Cossitt" wrote in message
...
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




Don Cossitt

Moidule Line # continued
 
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


"Trevor Shuttleworth" wrote in message
...
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


"Don Cossitt" wrote in message
...
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






Chip Pearson

Moidule Line # continued
 
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



"Don Cossitt" wrote in message
...
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


"Trevor Shuttleworth" wrote in
message ...
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


"Don Cossitt" wrote in message
...
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









All times are GMT +1. The time now is 10:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com