Lock cells

kwaring

New Member
Joined
Mar 14, 2002
Messages
49
Is there any way to lock cells so that a user cannot select or change them but let a macro change them?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Do a search for Protect or Unprotect and you will get all of the syntax you need...

You will obviously need to unprotect at the beginning of your macro and then Protect at the end.
 
Upvote 0
Hi

Yes there is! The Protect Method in VBA has an extra argument called "UserInterfaceOnly", by default this is False. If you howeve set it to True, any VBA code can change Object Properties, use Methods etc. I do however URGE you to read the help in the Excel VBE on "Protect Method" as the "UserInterfaceOnly" as it is wiped out after a save.

On a persoanl note I have found (in Excel 97 at least) that some operations, such as FillAcrossSheets does leave the Worksheet unprotected. For this reason I have avoided this and always used the:

Sub AnyOldCode()
Sheet2.UnProtect Password:="Secret"
On Error GoTo ReProtect
'Any Code
Reprotect:
Sheet2.Protect Password:="Secret
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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