Get start range and end range of a vertically merged cell with Excel using VBA

前端 未结 6 904
有刺的猬
有刺的猬 2020-12-10 13:02

I need to find out the first cell and the last cell of a vertically merged cell..

Let\'s say I merge Cells B2 down to B50.
How can I get in VBA the start cell(=B

6条回答
  •  星月不相逢
    2020-12-10 13:41

    Sub MergedAreaStartAndEnd()
    
        Dim rng As Range
        Dim rngStart As Range
        Dim rngEnd As Range
    
        Set rng = Range("B2")
    
        If rng.MergeCells Then
    
            Set rng = rng.MergeArea
            Set rngStart = rng.Cells(1, 1)
            Set rngEnd = rng.Cells(rng.Rows.Count, rng.Columns.Count)
    
            MsgBox "First Cell " & rngStart.Address & vbNewLine & "Last Cell " & rngEnd.Address
    
        Else
    
            MsgBox "Not merged area"
    
        End If
    
    End Sub
    

提交回复
热议问题