我不确定如何解决合并单元格对合并范围内每个单元格的核算,但我试图阻止用户选择彼此相邻的单元格组合并清除内容。
Sub PreventDeleteMultipleMergedCells()
If Selection.Count = 1 Then
Selection.ClearContents
Else
MsgBox "You cannot delete the contents of multiple selected cells."
End If
End Sub
我在研究中遇到了一个公共函数(见下文),但我不确定如何将输出放入子函数中,当选定的单元格> 1时,该子函数将触发 MsgBox。
Public Function MergedColumnsCount(c As Range) As Long
MergedColumnCount = 0
For i = 1 To c.Columns.Count
MergeColumnSize = c(i).MergeArea.Columns.Count
If MergeColumnSize > 1 Then
i = i + MergeColumnSize - 1
End If
MergedColumnCount = MergedColumnCount + 1
Next i
MergedColumnsCount = MergedColumnCount
End Function