Worksheet protection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to lock all of the cells in all worksheets that have formula's. I
have 26 pages and the formula's are in the same cells on each page.

I want to protect the formula's but the only way I can find to do this is by
protecting one page at a time. So everytime I need to change a formula, I
have to unprotect each page, change the formula, then protect each page
again. Is there a way to protect all of the pages at one time? When I try to
use the protection for the workbook, it doesn't seem to do anything.
 
Jeannine said:
I want to lock all of the cells in all worksheets that have formula's.
I
have 26 pages and the formula's are in the same cells on each page.

I want to protect the formula's but the only way I can find to do thi
is by
protecting one page at a time. So everytime I need to change
formula, I
have to unprotect each page, change the formula, then protect eac
page
again. Is there a way to protect all of the pages at one time? When
try to
use the protection for the workbook, it doesn't seem to do anything.

Try this: (you can prompt for a password too, if you want)

Sub ToggleProtection()
Dim aWorksheet As Worksheet
Dim res As Integer

res = MsgBox("Yes = Protect All Sheets, No = Unprotect All Sheets"
vbYesNo)

If (res = vbYes) Then
For Each aWorksheet In Worksheets
aWorksheet.Protect "MyPassword"
Next aWorksheet
Else
For Each aWorksheet In Worksheets
aWorksheet.Unprotect "MyPassword"
Next aWorksheet
End If

End Sub

Scot
 
I tried this but I get a VB error on the fourth line (the res=MsgBox etc
line.

Any ideas?

J.
 
This is all one logical line:

res = MsgBox("Yes = Protect All Sheets, No = Unprotect All Sheets", vbYesNo)
 
Thank you so much Maistrye, It works great. To run it I go to macro, run.
Is there a way to put a password on so that I can prevent other people from
running the macro?
 
Maybe...

Option Explicit
Sub ToggleProtection()
Dim aWorksheet As Worksheet
Dim Resp As String
Dim res As Integer

Resp = InputBox(Prompt:="Please enter a password to run")

If Resp <> "hithere" Then
MsgBox "nope!!!"
Exit Sub
End If

res = MsgBox("Yes = Protect All Sheets, No = Unprotect All Sheets", vbYesNo)

If res = vbYes Then
For Each aWorksheet In Worksheets
aWorksheet.Protect "MyPassword"
Next aWorksheet
Else
For Each aWorksheet In Worksheets
aWorksheet.Unprotect "MyPassword"
Next aWorksheet
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top