View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
gwinder gwinder is offline
external usenet poster
 
Posts: 14
Default Wrap text doesn't work when sheet is protected

I have been working on a employee review form that has unlocked merged cells.
I have the following event code that fires when there is no sheet
protection. However, as soon as I protect the sheet, the code doesn't fire.
If I unprotect after the text has been entered, then it will fire. Am I
missing something in the follwing code?

Thanks,

Gary

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
On Error Resume Next
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
On Error GoTo 0
Application.ScreenUpdating = True
End If
End With
End Sub