Autofit excelrow

  • Thread starter Thread starter Sofia Helin
  • Start date Start date
S

Sofia Helin

Is it possible to use autofit on a row,
and at the same time use "merge cells" on that row?

Or does anyone know how to show one or more rows of text in one mereged cell.
 
Hi Sofia,

I hope I understood you right:

You can show more than one row of text within one cell (if
merged or not) by using Alt+Return....

Besides: has this something to do with VBA? Maybe you
meant something else?

Best

Markus
 
You can use autofit on a row with a merged cell but autofit only looks at
the unmerged cells.

If you want to simulate autofit on a one row merged cell here's a macro that
may help:

''Simulates row height autofit for a merged cell if the active cell..
'' is merged.
'' has Wrap Text set.
'' includes only 1 row.
''Unlike real autosizing the macro only increases row height
'' (if needed). It does not reduce row height (because another
'' merged cell on the same row may needed a greater height
'' than the active cell).
Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth +
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End Sub


--
Jim Rech
Excel MVP
| Is it possible to use autofit on a row,
| and at the same time use "merge cells" on that row?
|
| Or does anyone know how to show one or more rows of text in one mereged
cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top