How to get find if a cell in excel is merged? If the cell mrged how to read the value?

后端 未结 4 522
日久生厌
日久生厌 2021-01-18 08:20

How do I detect if a cell in excel is merged?

If the cell is merged how do I read the value?

4条回答
  •  离开以前
    2021-01-18 08:57

    Hurray! Figured out a way to check whether a cell is merged and return that cell's value:

    Sub checkCellMerged1()
    'With ThisWorkbook.ActiveSheet
    Set ma = ActiveCell.MergeArea
    
    On Error GoTo errHand
    If ma = ActiveCell Then MsgBox ActiveCell.Address & " is not merged"
    GoTo final
    
    errHand:
    If Err.Number = 13 Then MsgBox "Merged Address = " & ma.Address _
    & vbCrLf & "Value = " & ma(1).Value
    
    final:
    On Error GoTo 0
    'End With
    End Sub
    

提交回复
热议问题