"Justify" Vertical Alignment does not work for Merged Cells

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Selecting "justify" for a cell's vertical alignment
automatically increases the row height (when "Wrap" is
also selected) as more or less text is added or removed
from the given cell.

But, if the same cell formating options are selected for
a group of Merged Cells, the automatic row height
function no longer works. Even double-clicking when
using the manual row height function does not work for
merged cells.

Does anyone have a fix for this problem?
 
Jim Rech has written some code to address this problem:

Jim Rech's code:

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


Regards,
Tom Ogilvy
 
Back
Top