View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.misc
cmungall cmungall is offline
external usenet poster
 
Posts: 5
Default Issue w/ Autofit Row Heights

Greg,

Thanks for your help here on the message boards! Your solution to the
Merged cell autofit looks like it could save me a lot of time!

One question, is there a way I can change the macro to set the merged cells
that have been autofit to be "unprotected" after the resize? I am using this
in a worksheet that is meant for others to use a guide and thus only leave
the cells meant for user input as unprotected. After the macro runs (and
works beautifully) the resized cells are no longer unlocked.

Any ideas?

"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