Sub CheckMergeStatus1()
Dim selectedCell As Range
Dim mergedRange As Range
Dim cell As Range
' 选择您要检查的单元格
Set selectedCell = ActiveCell
' 初始化合并范围为空
Set mergedRange = Nothing
' 遍历所有单元格,查找合并范围
For Each cell In selectedCell.Worksheet.UsedRange
If cell.MergeCells Then
If Not Intersect(selectedCell, cell.MergeArea) Is Nothing Then
Set mergedRange = cell.MergeArea
Exit For
End If
End If
Next cell
If Not mergedRange Is Nothing Then
MsgBox "选定的单元格位于合并范围内。合并范围是:" & mergedRange.Address
Else
MsgBox "选定的单元格不在合并范围内。"
End If
End Sub
联系客服