Quote:
Originally Posted by davesexcel
Interesting,
Looks like you had to to unlock all the cells first, and then lock the cells you want protected before you protect the sheet.
|
Yes, errors often occur when
Code:
Cells.Locked = False
Columns(1).Locked = True
ActiveSheet.Protect
Yes the first time it succeeds. But often I forgot to unprotect ActiveSheet before rerun the script
The second time when the sheet is protected, there should be an error when this code is run:
Code:
Cells.Locked = False
So I need:
Code:
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect
End If
''''''''''''''''''''''
Cells.Locked = False
Columns(1).Locked = True
ActiveSheet.Protect
I've heard advanced coders always say
it's good practice first to check before you code.
So "If a condition occurs do this; if not, do that."
should be done always to avoid "strange" errors.
It may prevent me from always asking questions.
I can work it out sometimes if it is practised.