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 "選定的單元格位于合并范圍內(nèi)。合并范圍是:" & mergedRange.Address Else MsgBox "選定的單元格不在合并范圍內(nèi)。" End If End Sub |
|