Excel adjust height of merged cells automatically

前端 未结 3 545
礼貌的吻别
礼貌的吻别 2021-01-03 16:45

I have a little problem in excel. I not experienced with excel macros and would be grateful for some help. I am trying to find a macro which ajustes the height of a merged c

3条回答
  •  耶瑟儿~
    2021-01-03 17:40

    What about this:

    'rRang is range of cells which are merged together
    
    Sub AutoFitRowMergedCells(rRang As Range)
    
    Dim iColW As Integer, iColWold As Integer, I As Integer
    
    iColW = 0
    
    For I = 1 To rRang.Columns.Count
        iColW = iColW + rRang.Range("A" & I).ColumnWidth
    Next I
    
    rRang.UnMerge
    iColWold = rRang.Range("A1").ColumnWidth
    rRang.Range("A1").ColumnWidth = iColW
    rRang.Range("A1").EntireRow.AutoFit
    rRang.Range("A1").ColumnWidth = iColWold
    rRang.Merge
    
    End Sub
    

提交回复
热议问题