ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Skip Errors (https://www.excelbanter.com/excel-programming/428870-re-skip-errors.html)

Barb Reinhardt

Skip Errors
 
I'm not sure I like the term "skip errors", I prefer to use "trap errors" and
give an example of how I do it.

Let's say I'm looking for a particular worksheet called 'Barbs Sheet'.

Dim myWS as Worksheet

Set myWS = nothing
on error resume next
Set myWS = Worksheets('Barbs Sheet')
on error goto 0

if myWS is nothing then
'Worksheet not found
else
'Worksheet found
end if

And do your execution from there. I'm in the process of modifying code in
a workbook that has On Error goto (Some grouping of lines), and untangling it
is a challenge, to say the very least.

I don't leave 'On Error Resume Next' on for very long, only long enough to
get through a line that *may* have an error until I can verify I have what I
want.
I find I need to add error trapping as I test, but I'd rather do it that way
than have it run all the way to the end and not know where the problem really
is.

HTH,
Barb Reinhardt
"Elton Law" wrote:

Dear Expert,

Can I set a script at the very beginning of the macro to overrule all errors
it encounter ?

That is ... it would not halt / stop ....
Even face errors ... immediately goto next line ....

A script at the beginning to rule this ....
Just go ahead and skip the error lines and keep on running with next line.

Thanks




All times are GMT +1. The time now is 09:47 PM.

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