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.
Is there any way to lock cells so that a user cannot select or change them but let a macro change them?
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
Like this thread? Share it with others