Hi all, my macro produces reports containing a lot of text in certain cells, and some of the cells are merged, preventing me from using the built in Excel "Auto height" function.
I found a sub that on this forum which automatically sets the row height so that all of the text in the selected cell fits in the visible area, even if the row contains merged cells:
It's pretty great, but it seems to be limited to a height of "255", so cells with a LOT of text still aren't completely displayed. Can anyone tell me why this might be? Is there a way to increase the limit?
I found a sub that on this forum which automatically sets the row height so that all of the text in the selected cell fits in the visible area, even if the row contains merged cells:
Code:
Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Long, MergedCellRgWidth As Long
Dim CurrCell As Range
Dim ActiveCellWidth As Long, PossNewRowHeight As Long
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
It's pretty great, but it seems to be limited to a height of "255", so cells with a LOT of text still aren't completely displayed. Can anyone tell me why this might be? Is there a way to increase the limit?