Protect unprotect formulas

Wimpie

Board Regular
Joined
Aug 12, 2008
Messages
210
Good day

Please assist with the below
I did a lot of research and found the below code that works , I only need all the cells with formulas protected and everything else to work
Code:
Sub Lock_Formulas()
    ActiveSheet.Protect "pass", True, True
    With ActiveSheet
     .Protect EnableOutlining = True
     .Protect UserInterfaceOnly = True
     .Protect DrawingObjects = True
     .Protect Contents = True
     .Protect Scenarios = True
     .Protect AllowFormattingColumns = True
     .Protect AllowFormattingRows = True
   End With
End Sub

The problem is that after unprotecting and protecting a few time I can not group (+) and ungroup (-) any more
How can I solve for this

I also need some code added to the below if the incorrect password as per the above is used to say "Incorrect password please try again" and to not create a Run-time error 1004 and direct me to developer to Debug
Code:
Sub Unlock_Formulas()
    ActiveSheet.Unprotect
End Sub

Thank you in advance
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Good day

Found the below in Google
Does exactly what is needed.

Hope someone else can use it as well, see the below
Code:
Option Explicit
Sub LockAll()
Dim ws As Worksheet
For Each ws In Worksheets
    ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:= _
        False, Password:="pass"
Next ws
End Sub
Sub UnLockAll()
    Dim ws As Worksheet
    Dim MyPassword As String
    MyPassword = InputBox("Enter Password.", "Password Entry")

    If MyPassword = "pass" Then
        For Each ws In Worksheets
            ws.Unprotect Password:="pass"
        Next ws
        
        MsgBox "All sheets are now unprotected.", vbCritical, "Sheets Unprotected"
    Else
        MsgBox "You entered an incorrect password.", , "Password Failed"
        Exit Sub
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top