troubleshooting Question

Event macro unprotects worksheet, then changes protection parameters - not what I want.

Avatar of eracer
eracerFlag for United States of America asked on
Microsoft OfficeMicrosoft Excel
1 Comment1 Solution185 ViewsLast Modified:
I use the following code to unprotect a worksheet and delete a row, retaining formulas and formats, but deleting constants, then turning protection on again..

Works great.

The problem is that I want to allow users of the protected worksheet to 'Select Unlocked Cells,' 'Select Locked Cells,' 'Format Cells,' but when the macro turns protection back on, the ability to format goes away, and all they can do is Select the unlocked and locked cells.

How can I lock in my protection parameters? (Disclaimer - I know very little, and have gotten this far by getting help here and by searching the web.)


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  'David McRitchie,  2007-09-07    insrtrow.htm on double-click
  '-- will copy more often than  Extend Formulas and Format (tools option)
  Cancel = True
  If Target.Row < 24 Then Exit Sub
  Sheet1.Unprotect Password:="Encore"
    Cells(Target.Row + 1, 1).EntireRow.Insert
  Cells(Target.Row + 1, 1).EntireRow.Select
  Application.CutCopyMode = False
  On Error Resume Next
  '-- customize range for what cells constants can be removed --
  Intersect(Selection, Range("a:IV")).SpecialCells(xlConstants).ClearContents
  ActiveCell.Offset(0, 2).Select
  Sheet1.Protect Password:="Encore"
  On Error GoTo 0
End Sub
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros