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.

VBA Worksheet_Changeイベントの制御

Last updated at Posted at 2022-03-11

エクセルのワークシートでChangeイベント利用時に、セルの値を変更する場合のイベント整理方法

Worksheet_Change

Public Const flg_Cancel_chgEvent as Boolean
'------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
    If flg_Cancel_chgEvent = True Then GoTo finaly_
finaly_:
End Sub

セルの値の書き換え処理の前後

 flg_Cancel_chgEvent = True:    Me.Unprotect
  Target.Offset(1, 0).Value = "↑ 未登録"
 flg_Cancel_chgEvent = False:    Me.Protect

注意点

イベントキャンセル、プロテクトon は抜け漏れがでやすい
→ セルの値の変更前後に、この処理を入れること
親プロセス
子プロセスに逐一書く

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?