Goos van den Bekerom
Goos van den Bekerom

Reputation: 1493

Excel VBA - Is it possible to call sub on error?

I've been searching, but I can't really find something that answers this question.

I'm getting an error and I know whats causing it and it not really a problem. It just needs to run another sub before running the next line of code if this error occurs. So that made me wonder:

Is it possible to do something like this:

On Error Call Sheet1.TestSub

Thanks in advance!

Upvotes: 0

Views: 20477

Answers (2)

aebailey
aebailey

Reputation: 195

You could try something like this:

Sub test()
On Error GoTo 10
Set a = b
MsgBox ("still going")

Exit Sub
10:  test2
Resume Next

End Sub

Sub test2()
MsgBox ("Error")

End Sub

Upvotes: 9

Gary's Student
Gary's Student

Reputation: 96753

No.

The best you can do is to branch to a separate section of code to handle the error and then branch back to the line immediately below the line raising the error. (if you know what that line is!)

Upvotes: 2

Related Questions