Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Autofit Merged Cells in Excel

2,038 views
Skip to first unread message

kchambers

unread,
Mar 4, 2005, 11:59:04 AM3/4/05
to
I have tried to use Jim Rech's macro to autofit a merged cell in excel.
However, I cannot seem to get this to work for my situation. I have (1) row
merged in (2) columns (D & E.) What am I doing wrong???

Jim Rech

unread,
Mar 4, 2005, 12:32:49 PM3/4/05
to
There are three requirements and you mentioned 2. Is Wrap Text set for the
active cell?

--
Jim Rech
Excel MVP
"kchambers" <kcha...@discussions.microsoft.com> wrote in message
news:B18253BC-C422-417C...@microsoft.com...

kchambers

unread,
Mar 4, 2005, 12:43:04 PM3/4/05
to
Yes, I do have wrap text selected.

Jim Rech

unread,
Mar 4, 2005, 2:12:53 PM3/4/05
to
You didn't specify exactly how it fails. Just in case the problem is that
the macro is not shrinking the row height, I should mention it is design
only to increase row heights if needed. The reason being that there could
be other merged cells on the same row that need the greater row height.

Maybe you could copy/paste the problem merged cell into a new workbook and
send it to me, once you verify that the problem reproduces in it of course..

--
Jim Rech
Excel MVP
"kchambers" <kcha...@discussions.microsoft.com> wrote in message

news:2CB664C0-90C6-47B0...@microsoft.com...

kchambers

unread,
Mar 4, 2005, 2:43:04 PM3/4/05
to
Jim,
The row height is not expanding to fit all the characters within the cell.
I am not very familar with macros. I just started working on them last week.
I don't mind sending you the workbook so you can look at it. How do I get
your email address?

Jim Rech

unread,
Mar 4, 2005, 4:17:57 PM3/4/05
to
jrr...@hotmail.com

--
Jim Rech
Excel MVP
"kchambers" <kcha...@discussions.microsoft.com> wrote in message
news:28F5C75E-4A13-47FF...@microsoft.com...

Jim Rech

unread,
Mar 5, 2005, 11:57:51 AM3/5/05
to
Kelli's merged cell did not have word wrap set for the entire merged cell,
just the first cell in it. This is a situation I hadn't anticipated but an
easy shortcoming to fix (I think):

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 .Cells(1).WrapText = True Then
''<<.Cells(1) added
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


--
Jim Rech
Excel MVP

"Jim Rech" <jrr...@hotmail.com> wrote in message
news:Oqghj%23PIF...@TK2MSFTNGP14.phx.gbl...

0 new messages