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

前端 未结 6 863
有刺的猬
有刺的猬 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:38

    Below macro goes through all sheets in a workbook and finds merged cells, unmerge them and put original value to all merged cells.

    This is frequently needed for DB applications, so I wanted to share with you.

    Sub BirlesenHucreleriAyirDegerleriGeriYaz()
        Dim Hucre As Range
        Dim Aralik
        Dim icerik
        Dim mySheet As Worksheet
    
        For Each mySheet In Worksheets
    
        mySheet.Activate
        MsgBox mySheet.Name & “ yapılacak…”
    
        For Each Hucre In mySheet.UsedRange
            If Hucre.MergeCells Then
               Hucre.Orientation = xlHorizontal
               Aralik = Hucre.MergeArea.Address
               icerik = Hucre
               Hucre.MergeCells = False
               Range(Aralik) = icerik
            End If
        Next
    
     MsgBox mySheet.Name & " Bitti!!"
    
     Next mySheet
    End Sub
    

提交回复
热议问题