0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

テスト86

Posted at
Sub Error_test()

'「On Error GoTo Err_Exit」を通すか通さないかによって、
'エラーがあった時に、以下のように処理を分けられる
'1,止めずに後処理をする
'2,止めてどこでエラーがあったかわかるようにする

'この処理を作った理由は、1のように通常通りエラー処理をすると
'エラーメッセージは出せるけどエラー処理で終了してしまい、具体的に
'どのコードでエラーがあったかわからなくなってしまうため。

'そのため2をできるようにしたのが以下のコード

With ThisWorkbook.Sheets("テスト2")

    If .Range("A1").Value = 1 Then
    
        On Error GoTo Err_Exit
    
    End If

End With

'A1セルを空欄にした場合、以下のコードで止まる
Err.Raise 11111

Exit Sub

Err_Exit:
'A1セルを1にした場合、以下のコードでエラーメッセージを出して終了
MsgBox Err.Number & vbCrLf & Err.Description


End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?