Lock/Unlock Spreadsheet in VBA

pancaked

New Member
Joined
Jan 14, 2016
Messages
3
Hi,

I've got a spreadsheet with 20+ worksheets and many VBA scripts. I have set up basically a "control panel" where users can run any of the macros to interact with the spreadsheet. My intention is that they use these macros only and do not alter any of the cells the spreadsheet.

I'd like to lock all the cells in the entire spreadsheet (well, most cells, with a few exceptions) so they cannot be altered manually -- but the macros would still need to be able to alter cells.

Is there a simple or elegant way to accomplish this?

Thanks!
 
protect the sheet programmatically with:

Worksheets(sheetname).protect userinterfaceonly:=true

this allows code to change values on sheets, but not the user. Even if the cell is locked.
note that if you want filtering to work, you'll have to add more arguments. Just look up Protect in help. Or record the settings you want and then add userinterface
 
Upvote 0

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