maximoomoo
Board Regular
- Joined
- Jun 27, 2006
- Messages
- 62
I have a cell that is 8 columns wide and 14 rows deep. The cell is merged and has wrap text applied.
The cell is being used to manually enter text and I would like the size of the cell to automatically adjust depending on the content.
I have applied the following code which re-adjusts the cell size if it is just 1 row, rather than the 14 rows.
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
The does in fact work well if the cell is made up of 1 row rather than several, however the document involved is a report that needs to be printed out. At the moment, if I type text that is bigger than the current size of cell then it moves the entire cell onto the next page, which is understandable as it is 1 row. What I would like is just the overflow of text to move onto the next page, which obvioulsy means the cell needs to be made up of several rows.
Also, not sure if it is relevant, but I am using Alt-Enter in the cell to create returns.
Any ideas on how to resolve this?
Thanks
Max
The cell is being used to manually enter text and I would like the size of the cell to automatically adjust depending on the content.
I have applied the following code which re-adjusts the cell size if it is just 1 row, rather than the 14 rows.
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
The does in fact work well if the cell is made up of 1 row rather than several, however the document involved is a report that needs to be printed out. At the moment, if I type text that is bigger than the current size of cell then it moves the entire cell onto the next page, which is understandable as it is 1 row. What I would like is just the overflow of text to move onto the next page, which obvioulsy means the cell needs to be made up of several rows.
Also, not sure if it is relevant, but I am using Alt-Enter in the cell to create returns.
Any ideas on how to resolve this?
Thanks
Max