PDA

View Full Version : Skip a fault 13 with an If code and go on with the macro



Brunop
11-17-2017, 06:02 AM
Dear all,


I have a problem with my vba/macro. It suddenly has a problem with a value in a cell. Fault 13. Types doesn’t match. In some cells there is Indeed a diffrent type. But is it possible to skip the macro for that line and go to the Next?


Thx for the help.

SamT
11-17-2017, 07:22 AM
But is it possible to skip the macro for that line and go to the Next?
Yes it is possible.

Jan Karel Pieterse
11-17-2017, 07:50 AM
Example:


Sub SkipDemo()
Dim oCell As Range
On Error GoTo LocErr
For Each oCell In Selection
If oCell.Value = 10 Then
'Warning, an error 13 still ends here!
MsgBox "10!"
End If
Next
Exit Sub
LocErr:
If Err.Number = 13 Then
MsgBox "Error 13!"
Resume Next
Else
MsgBox "Unexpected error!" & vbNewLine & Err.Number & vbNewLine & Err.Description, vbExclamation + vbOKOnly
Stop
'Resume gets you to the offending line of code:
Resume
End If
End Sub