Link to home
Start Free TrialLog in
Avatar of John Darby
John DarbyFlag for United States of America

asked on

Excel protection, need to enable hide/unhide for users while protected

I have a routine which protects all cells in the workbook which contain formulas. I need to add to this routine an instruction to enable the user to hide/unhide. At the moment, if protection is enabled, the user cannot hide/unhide columns and rows.
Thank you!
JohnD
Sub prot()
Dim rng As Range
Dim prot As Range
Dim ws As Worksheet
 
    For Each ws In ThisWorkbook.Worksheets
        If ws.ProtectContents = True Then ws.Unprotect
        ws.Cells.Locked = False
        On Error Resume Next
        Set prot = ws.Cells.SpecialCells(xlCellTypeFormulas, 23)
        On Error GoTo 0
        If Not prot Is Nothing Then
            prot.Locked = True
            For Each rng In prot
                If rng.Parent.ProtectContents = False Then rng.Parent.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
            Next
        End If
        Set prot = Nothing
    Next
 
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Darby

ASKER

Thank you for the below statements!

AllowFormattingColumns:=True,AllowFormattingRows:=True