lock remaining cells in protected sheet

huli601

New Member
Joined
Oct 25, 2015
Messages
7
Hi,

I use workbook with 62 sheets (number of shifts in month). On every sheet are lock and also unlock cells, sheet is protected by password, so users are allow edit only unlock cells. I try to find easiest way to lock remainig unlock cells (for example some macro by clicking on button). Than whole sheet will by protected by password.

thank you.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
In your command button module, paste this code;

Code:
    Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Worksheets
        ws.Cells.Locked = True
        ws.Protect Password:="Password"
    
    Next

And just change the "Password" to whatever you want it to be.

This will format all cells to 'Locked' and then password protect each worksheet you have.

Is this what you were looking for?
 
Upvote 0
Try
Code:
Sub Test()
   Dim ws As Worksheet
   
   For Each ws In ActiveWorkbook.Worksheets
      ws.Unprotect "Password"
      ws.Cells.Locked = True
      ws.Protect "Password"
   Next
End Sub
 
Upvote 0
Sorry huli, I didn't account for some worksheets already being protected

Fluff's one should work perfectly.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,114
Members
453,021
Latest member
Justyna P

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