Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking Editable Cells in excel

Status
Not open for further replies.

jvet4

Technical User
Jul 24, 2000
54
US
I have an excel workbook using the Solver add-in. In my workbook, I am using solver to optimize a group of cells, however I do not want the user to be able to modify the cells. When I try to lock the sheet and run the solver macro, I get an error saying the sheet is protected therefore read-only. I have tried to lock the sheet allowing the user to edit objects/scenarios but that does not to work. Is there a way to lock a worksheet so that a VBA script can still edit cells, however the user cannot?
 
You'll need to add some unprotect/protect code to your macro.

Code:
ActiveWorkbook.UnProtect "ThePassword"
........
'your code here
.............
ActiveWorkbook.Protect "ThePassword"
 
OOps!, that code is for the workbook, you may not want that.

I meant to say:
Code:
ActiveWorksheet.UnProtect "ThePassword"
........
'your code here
.............
ActiveWorksheet.Protect "ThePassword"
 
There is indeed - you need to put this code in your workbook_OPEN event as it is reset when the workbook is closed

Sheets("Sheetname").protect userinterfaceonly:=true

This will mean that code can run unhindered but users cannot edit locked cells Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top