Hello -
I have created a form in Excel where users will supply updates to me and print the page for their records. I am having an issue now with wrapped text in certain cells where some has typed more than what will display in the standard cell height. I have these cells set to wrap text, and it does, but the rows are still not tall enough to show what they typed. Is there a way to automatically re-size the height of cells when text wraps like this?
I did some looking around this morning, and found a code, but I am getting an error in Excel at the line in bold below. If someone online now has a few minutes to take a look at this code, and give me any insights I would be extremely thankful! I have spent an hour now this morning trying to get something to work... Thanks!
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
I have created a form in Excel where users will supply updates to me and print the page for their records. I am having an issue now with wrapped text in certain cells where some has typed more than what will display in the standard cell height. I have these cells set to wrap text, and it does, but the rows are still not tall enough to show what they typed. Is there a way to automatically re-size the height of cells when text wraps like this?
I did some looking around this morning, and found a code, but I am getting an error in Excel at the line in bold below. If someone online now has a few minutes to take a look at this code, and give me any insights I would be extremely thankful! I have spent an hour now this morning trying to get something to work... Thanks!
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