title: how to make visual basic work on protected worksheets (no password on protection)
body: <p>I have a work book with several worksheets that I would like to protect. I am not using a password on the protection. I have some visual basic code associated with this sheet to expand the row width on merged cells. The code will not work when the sheets are protected.</p>
  
  <p>I did find some guidance on adding unprotect code to my code, but can't figure out where to put it and how to address the fact that there is no passord. Further guidance woudl be greatly appreciated! </p>
  
  <p>Here is my code:</p>
  
  <pre><code>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
  </code></pre>