Error handling with GoTo

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm not quite sure how to title what I'm trying to ask.

But basically I have a module running that at various points throughout requires some custom error handling which is basically If some value = whatever GoTo manual.

There are a few points throughout the code that can trigger GoTo manual (its not possible to have them all at the start unfortunately as some errors only become apparent as the code works through what its doing).

Originally, I wasn't using GoTo - I was simply writing the same handling code again and again (its a message box, do something, and then return to the start of the code (its a fairly big loop and the code runs again and again until its processed the data required)). Instead of doing that, and for ease of handling further errors I decided to create a GoTo "manual" where manual handles the aforementioned "do something" bit of code.

But I'm wondering how to place the "manual:" bit of code on the module - its currently at the end of my code, but I'm thinking, well if I'm processing a bit of data with no error triggers, it'll get to the end and still try to run whatever is after "manual:" won't it? it wont know to skip over this part of code.

So should it be another sub in the same module? but then GoTo doesnt work? or should I create another GoTo which is at the end of my code (before manual:) which can only be reached if the data has zero errors which simply skips over manual?

Sorry if that's a bit wordy. I'm just not sure what best practice is and I don't quite have the lingo to describe my problem cleanly

thanks all
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can just put Exit Sub before the Manual: line.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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