View Single Post
 
Old 04-08-2012, 09:58 PM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by davesexcel View Post
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.
Reply With Quote