View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] mauricemeijerink@gmail.com is offline
external usenet poster
 
Posts: 3
Default unlocking merge cells

Hi all

I found a code to use on merged-cells to auto-change the row height
after updating the cell content. I changed the code a little but now I
found a problem that I can not solve, maybe someone can help me out.
The problem is: After updating the row-heigt the (unlocked) merged-
cells are getting locked, so they can't be changed when the sheet is
protected. I don't want the cells to be locked, the cells are not in a
specific range.

The code I use is:

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

With Target
If .MergeCells And .WrapText Then
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
OldRwHt = c.RowHeight
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

If NewRwHt OldRwHt Then
ma.RowHeight = NewRwHt
Else
ma.RowHeight = OldRwHt
End If

cWdth = 0: MrgeWdth = 0: OldRwHt = 0
Application.ScreenUpdating = True

End If
End With
End Sub

Please, can someone help me out.

gr.

Maurice