Solved

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

Posted on 2014-11-24
4
99 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now