View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Issue w/ Autofit Row Heights

Don't know why the first set of code will not work for you.

What does "does not work" mean to you?

Nothing happens? The wrong thing happens?

The code that Greg posted is placed in a different module than the code we
originally looked at.

Greg's is event code not regular macro sub routine.

To use the code in this post, copy it.

Select the sheet tab in your workbook and "View Code"

Paste into that module.


Gord Dibben MS Excel MVP


On Tue, 25 Jul 2006 12:56:02 -0700, bbddvv
wrote:

what is this new code? It didn't work even though i fixed the line of code
that was on 2 lines. Ugh.



"Greg Wilson" wrote:

The code you posted was originally developed by Jim Rech. This is an adaption
of his code from a recent post of mine. Paste to the worksheet's code module.
To do so, right click the worksheet's tab and select View Code to access the
code module. Also, ensure that the WrapText property of the merged cells is
set to True through Format Cells Alignment tab.


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

Regards,
Greg