Excel - Autofit Row Height

I use ALT+Enter to add another text line within the same cell.  Some single cells have up to 4 to 6 lines.  Now I want to use Autofit by double clicking the row line to Autofit the row height. However, when I do this the row adjusts to only show the top line of text in the cell and not all 4-6 lines.  Is there a way to Autofit and show all lines in the cell?
Hank IsaacsEngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

is the cell with Wrap Text ticked?

Regards
0
Hank IsaacsEngineerAuthor Commented:
same thing happens whether the cell has wrap text turned on or off.
0
Rgonzo1971Commented:
Could you send a dummy?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Hank IsaacsEngineerAuthor Commented:
0
Rgonzo1971Commented:
Now I see

It cannot autofit because of the merged Cells

Regards
0
Hank IsaacsEngineerAuthor Commented:
So how do I Autofit multiple lines?
0
Rgonzo1971Commented:
You could use this macro

select the merged cell to be adjusted

Sub AdjustHeightMergedCell()

MrgAddr = ActiveCell.MergeArea.Address
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

End Sub

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hank IsaacsEngineerAuthor Commented:
I appreciate your help, but I can simply adjust and drag the row line underneath.  I was looking for a way to double click a row line and all lines would AutoFit height.
0
Ejgil HedegaardCommented:
Try this, with Rgonzo1971 code expanded to adjust all merged cells on the sheet.
It looks a bit complex for that, but it is to only adjust once for each area of merged cells.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.