Error Handling Multiple Errors in Excel VBA or Macros - Code Included

Опубликовано: 28 Сентябрь 2024
на канале: EverydayVBA
6,182
35

Grab the Free VBA Quick Reference Guide
https://chrisjterrell.com/p/getting-s...
If you have multiple errors in your code you may need to handle it in two very different ways in this video we show you how to use mulitple On Error Goto Statments to solve two unique issues.

We also use err.Number and err.Description

Code:
=============
Sub Shapes_Comments()
On Error GoTo errboth
'On Error GoTo err1
x = 0
d = 0 / x


'On Error GoTo err2
Range("B9").Comment.Text Text:="Add this Text"


Exit Sub
err1:

x = 1
Resume

Exit Sub
err2:

Range("B9").AddComment
Resume

Exit Sub
errboth:

If Err.Description = "Overflow" Then
x = 1

ElseIf Err.Number = 91 Then
Range("B9").AddComment
End If
Resume


End Sub