Locking all cells in a sheet

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
How do I lock all cells within a sheet?

I have a sheet which I don't want the user to be able to input anything onto. I still need the command buttons on the sheet to work, but the user shouldn't be able to select the cells.

I've looked on a couple of site but don't seem to be able to get this to work.

Thanks for any help
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
By default all of the cells on a worksheet are locked, so all you need to do is protect the sheet. Command buttons will work on protected sheets, but you might need to tweak your code a bit if it's doing anything to the sheet. Fortunately that's relatively simple:

Code:
Activesheet.Unprotect "PasswordHere"
  '  Your code
Activesheet.Protect "PasswordHere"

HTH
 
Upvote 0
I'm using 2010.

and Smitty, there isn't any code doing anything on this page. Do I just create a sub and put it in the 'general' code on the page?

Here is my code for it at the moment

Code:
 Sub Protectthesheet()
ActiveSheet.Protect "mypassword"
End Sub

Where am I going wrong?
 
Upvote 0
What do your command buttons do?

If you don't have any code now, then there's really no reason to introduce any. I'd just protect the worksheet manually - you'll find the commands on the Review tab.

As for the code you came up with, yes, you'd add a module and paste the code in there. You can call it manually from the Developer tab, run it from the VBE with F5, or assign it to a button.
 
Last edited:
Upvote 0
I have loads of code in the workbook, just none on that sheet directly. The command buttons run macros which open forms and sheets, print, save, etc.

Have got it working now, for when the workbook is opened. For some reason the unprotect password was already set to "password" (I found this by guessing). It all works fine now with a new password.
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

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