PDA

View Full Version : Autofit Merged Cells / Autosize Formatting



sherryjoo
01-19-2011, 11:12 AM
I know it sounds simple, but I'm having no luck with it...

How do you autofit, specifically row height, on a merged cell?

Thank you!

mancubus
01-19-2011, 12:07 PM
a quick search in google makes me think it's a problem of mankind :think: :rofl:

http://groups.google.com/group/microsoft.public.excel.programming/browse_frm/thread/a5cbe0ee8e6c2a10/93c6bca447bd8902#93c6bca447bd8902

p45cal
01-19-2011, 12:28 PM
If the merged cells are on the same row, you might try 'Centre across selection' for the horizontal alignment instead of merging the cells, and 'wrap text' checked. Then double click the lower border of the row's label?

sherryjoo
01-19-2011, 01:08 PM
Thank you so much for your time. I will try these out tomorrow!

sherryjoo
01-20-2011, 09:22 AM
The google link gave me an error message, but I did fild this code from Greg Wilson, which works great except if you have two merged cells in the same row (I have no control over the format, so I can't delete the dread merged cells). If you have a11 & b11 merged and c11 & d11, it's going to size the row height according to the last change event, not the larger of the merged cells. Does anyone have any ideas around this? Thanks again!!!

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range

With Target
If .MergeCells And .WrapText Then
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
Application.ScreenUpdating = True
End If
End With
End Sub