イベントを処理するときは、次のChange3 つのシナリオを考慮する必要があります。
TargetUnmerged細胞のみからなる
Target単一のMerged範囲のみで構成される
Target1 つ以上のMerged範囲と 0 個以上のUnmergedセルで構成される
Range.MergeCellsプロパティは、次の可能性を明らかにします。
Range.MergeCells = FALSE
Range.MergeCells = TRUE
Range.MergeCells = NULL
範囲内の各セルを個別に調べて、どれがマージされているかを確認Range.MergeCells = NULLする必要がある場合Target
このようなもの
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cl As Range
If IsNull(Target.MergeCells) Then
'Changed Range contains one or more Merged cells and other cells
For Each cl In Target.Cells
If cl.MergeCells Then
' only consider top left cell of a merged range
If cl.Address = cl.MergeArea.Cells(1, 1).Address Then
If cl = "" Then
MsgBox "Merged Cell Deleted " & cl.MergeArea.Address
End If
End If
End If
Next
Else
If Target.MergeCells Then
' Changed Range is a single Merged cells
If Target.Cells(1, 1) = "" Then
MsgBox "Merged Cell Deleted " & Target.Address
End If
Else
'Changed Range is Unmerged cells only
End If
End If
End Sub