I'm reading up on how to use On Error Resume Next
and I'm trying to figure out how long that line will apply to the program. On the Microsoft site, I found this sentence: "An On Error Resume Next statement becomes inactive when another procedure is called." What exactly does this mean? What is considered to be a procedure?
I ask because I'm using the line in my program, but I don't want it to Resume Next
all the runtime errors which occur, just the obvious one on the next line.
Code:
Dim zRange As Range
Call FilterTableFor(fieldNameColumn, Array("baseunitprice", "burden", "MTLBURRATE", "PurPoint", "Vendornum"))
On Error Resume Next
Set zRange = commentsColumnRange.SpecialCells(xlCellTypeVisible)
zRange.Formula = "target"
Call FilterTableFor(fieldNameColumn)
I've also found (and known for a while) that On Error
or GoTo
lines are considered poor coding. Is there a Try-Catch
which I can use for a line like this?
I'm thinking something like this:
Dim zRange As Range
Call FilterTableFor(fieldNameColumn, Array("baseunitprice", "burden", "MTLBURRATE", "PurPoint", "Vendornum"))
Try
Set zRange = commentsColumnRange.SpecialCells(xlCellTypeVisible)
zRange.Formula = "target"
Catch()
Call FilterTableFor(fieldNameColumn)
Where I don't even do anything with it, as I don't feel a need to.
Thanks for your time.
SCOPE OF ON ERROR...
STATEMENT
The effec5 of ON ERROR ...
ends as soon as one of the following is encountered:
ON ERROR ...
. (Maybe in the form of ON ERROR RESUME x
or ON ERROR GOTO x
)Exit Sub
/ Exit Function
within the same sub/function where defined.End Sub
/ End Function
of the sub/function where defined.IS IT BAD TO USE ON ERROR RESUME NEXT
?
Yes and No.
I would say don't use without knowing what the effect of this statement would be. Avoid if possible. Keep the scope short wherever not possible.
To nullify the effect of an ON ERROR RESUME NEXT
statement, you can call ON ERROR GOTO 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With