VBA spreadsheet “Protect and Unprotect” multiple workbooks

mike575

New Member
Joined
Apr 24, 2024
Messages
2
Office Version
  1. 365
  2. 2011
Platform
  1. Windows
i have a spreadsheet that contains multiple work sheets and within each i have certain cells "locked" and others "unlocked". i have a button for protecting which it performs and protects all the workbooks but when i need to do a "data" clear in the cells that are unlocked it states this
1713973999083.png
and if i debug it throws this up
1713974064016.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
If the sheet is protected, the code will have to unprotect it, perform the clear contents and then protect it again. Change the password ( in red) to suit your needs. You don't have to activate the sheet to do that. For example:
Rich (BB code):
With Sheets("January")
    .Unprotect Password:="XXX"
    .Range("C9:AG135").ClearContents
    .Protect Password:="XXX"
End With
 
Upvote 0
If the sheet is protected, the code will have to unprotect it, perform the clear contents and then protect it again. Change the password ( in red) to suit your needs. You don't have to activate the sheet to do that. For example:
Rich (BB code):
With Sheets("January")
    .Unprotect Password:="XXX"
    .Range("C9:AG135").ClearContents
    .Protect Password:="XXX"
End With
thanks
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,568
Members
449,237
Latest member
Chase S

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