I have designed a report contains VBA code (call it the "Filler code") that allows users to fill the report with data that comes from several other spreadsheets. Other people in the company had set the report format up and I'm more or less stuck with the report template that they have developed. Unfortunately it has a lot of merged cells. A quick Google search gave me the following code to adjust row height on merged cells:
It works excellently. But it seems to only work when we're only merging columns and not rows. Is there a way to do this when we're merging rows?
I have the above code placed in a regular module but call it from the Worksheet Change event. I was expecting to see the height adjustment code run each time that the Filler code placed data into a cell on the report. Is there a way that I can get the height adjustment code to run each time that the Filler code inputs data? Or is there a better way to do this, such as to go through each cell in the report once I'm done and have it auto adjust at that time?
Thanks in advance and sorry for having such a muddled question/explanation.
Code:
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
It works excellently. But it seems to only work when we're only merging columns and not rows. Is there a way to do this when we're merging rows?
I have the above code placed in a regular module but call it from the Worksheet Change event. I was expecting to see the height adjustment code run each time that the Filler code placed data into a cell on the report. Is there a way that I can get the height adjustment code to run each time that the Filler code inputs data? Or is there a better way to do this, such as to go through each cell in the report once I'm done and have it auto adjust at that time?
Thanks in advance and sorry for having such a muddled question/explanation.