Solved

MS Excel how to auto size row height when cells are merged

Posted on 2014-11-24
4
105 Views
Last Modified: 2014-11-25
How do I enable auto size of an excel row height when cells are merged and I have text wrapping enabled? I can't un-merge the cells,
0
Comment
Question by:mvp1985
  • 2
4 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40462461
I don't think you can. It's a big nuisance. Sorry.
0
 

Author Comment

by:mvp1985
ID: 40462482
Is it fixable by Macro?
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40462503
Here's an interesting way around the problem without a macro - http://excel.tips.net/T003207_Automatic_Row_Height_For_Merged_Cells_with_Text_Wrap.html

May or may not work - try it out!
0
 
LVL 21

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
ID: 40462540
Try this

Option Explicit

Sub AdjustHeightMergedCell()
Dim MrgAddr As String, rngMergeArea As Range, c As Range, cellWidth As Double, MrgWidth As Double, rwHeight As Double
Dim ws As Worksheet, cl As Range, MergeList() As Variant, i As Long, j As Long, k As Long, l As Integer

    Application.ScreenUpdating = False
    Set ws = ActiveSheet
    ws.Rows.AutoFit
    i = 0
    For Each cl In ws.Range(Cells(1, 1), Cells(ws.Cells.SpecialCells(xlCellTypeLastCell).Row, ws.Cells.SpecialCells(xlCellTypeLastCell).Column))
        If cl.MergeArea.Address <> cl.Address Then
            i = i + 1
        End If
    Next cl
    ReDim MergeList(1 To i, 1 To 2)
    i = 0
    For Each cl In ws.Range(Cells(1, 1), Cells(ws.Cells.SpecialCells(xlCellTypeLastCell).Row, ws.Cells.SpecialCells(xlCellTypeLastCell).Column))
        If cl.MergeArea.Address <> cl.Address Then
            i = i + 1
            If i = 1 Then
                MergeList(i, 1) = cl.Address
                MergeList(i, 2) = cl.MergeArea.Address
                j = 1
            Else
                l = 0
                For k = 1 To j
                    If MergeList(k, 2) = cl.MergeArea.Address Then
                        l = 1
                    End If
                Next k
                If l = 0 Then
                    j = j + 1
                    MergeList(j, 1) = cl.Address
                    MergeList(j, 2) = cl.MergeArea.Address
                End If
            End If
        End If
    Next cl
    For i = 1 To j
        MrgAddr = MergeList(i, 2)
        Set rngMergeArea = Range(MrgAddr)
        With rngMergeArea
            .UnMerge
            cellWidth = .Cells(1).ColumnWidth
            MrgWidth = 0
            For Each c In rngMergeArea
                c.WrapText = True
                MrgWidth = c.ColumnWidth + MrgWidth
            Next
            .Cells(1).ColumnWidth = MrgWidth
            .EntireRow.AutoFit
            rwHeight = .RowHeight
            .Cells(1).ColumnWidth = cellWidth
            .MergeCells = True
            .RowHeight = rwHeight
        End With
    Next i
End Sub

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question