| 
    
     |  | '----------------------------------------------------------- '※方法1 attentionを初期化するコードを追加する
 '-----------------------------------------------------------
 Option Explicit
 Public attention As Byte
 
 Sub A1()
 attention = 0 'B1実行前にattentionを初期化
 
 B1 'プログラムを実行するか否かを判断 B1 を呼ぶ
 If attention = 1 Then 'attention=1の場合は、実行=否と判断し、終了する。
 MsgBox "終了", vbExclamation
 Exit Sub '#1
 End If
 
 C1
 End Sub
 
 Sub B1() 'プログラムを実行するか判断する
 If Cells(1, 1) = 1 Then '#2
 attention = 1
 Exit Sub
 End If
 End Sub
 
 Sub C1() '実際に計算したい内容
 Cells(2, 1) = Cells(3, 1) + Cells(4, 1)
 End Sub
 
 '-----------------------------------------------------------
 '※方法2 B1をFunctionにする
 '-----------------------------------------------------------
 Option Explicit
 Sub A1()
 If B1 Then 'B1の戻り値=Trueの場合は、実行=否と判断し、終了する。
 MsgBox "終了", vbExclamation
 Exit Sub '#1
 End If
 
 C1
 End Sub
 
 Function B1() As Boolean
 'プログラムを実行するか判断する
 If Cells(1, 1) = 1 Then '#2
 B1 = True
 Else
 B1 = False
 End If
 End Function
 
 Sub C1() '実際に計算したい内容
 Cells(2, 1) = Cells(3, 1) + Cells(4, 1)
 End Sub
 
 
 オススメは後者(方法2)です。
 
 
 |  |