Error handling - jump to line

Ace71425

Board Regular
Joined
Apr 20, 2015
Messages
130
Hello all...I was looking for a way to implement a line of code that on error jumps to a specific line...there are a couple instances of my code that in some circumstances I really need it to jump if there is an error. .if there were a way to do it something like On Error GoTo Line 37 could I just put that anywhere in the code? AND would it have to specify the line of that sub or the line of the code on that page in total? In example I have 3 subs so would it be line 200 even though it's technically the second line of that sub? Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Ace,

Sounds like you're talking "Labels". Just a word followed by a colon. There are naming rules, probably similar / same as variable names. See VBA help on "Labels"

It looks something like the sample below which I believe is what you're describing:

Code:
Public Sub Sample()

Dim MiscVariables

On Error GoTo MyLabelForError

'Do Stuff
'Do More Stuff

GoTo SkipLoop ' Using goto to jump around is hard to follow and not considered good practice

'This loop won't execute
For X = 1 To 5
    Debug.Print X
Next X

SkipLoop: 'Label named SkipLoop see VBA help for label naming rules

'Do Stuff
'Do More Stuff

Exit Sub 'Skip over error handling code

MyLabelForError:  'Label named MyLabelForError see VBA help for label naming rules

    'Handle Error
    Resume Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,222,382
Messages
6,165,647
Members
451,983
Latest member
Raph24

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