How can I trap only particular errors in VBA?
So far I have been raising another error with same number in error handler( the one that I don't want to use for this particualr error) to pass the error to another handler, but that makes my code bloated.
I was wondering if there is a better way?
Example of how I have been doing this thus far:
sub correct()
On Error GoTo CorrectHandler
wrong
CorrectHandler:
'some code to handle out of range error (aka Err.Number 9)
End Sub
Sub wrong()
Dim BadArray(1 To 1) as Variant
On Error GoTo WrongHandler
BadArray(100) = 1
WrongHandler:
Select Case Err.Number
Case 9
Err.Raise 9
'Code to handle other errors
End Select
End Sub
code to handle out of range errorin its own procedure and calling it from whichever error handler you want?