Solved

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

Posted on 2014-11-24
4
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 23

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

623 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