Reputation: 1
I created a button and code to LOCK (or protect) the sheets in my workbook. I also created a button and code to UNLOCK (or unprotect) the sheets in my workbook.
I have columns I want the user to be able to enter info; but I do not want the whole sheet unlocked/unprotected.
Example on my Training sheet, cells K6:U3175 I'd like unprotected. Here's what I've tried:
'This is for the Lock Button on the WOOKBOOK TIPS sheet.
'Upon clicking once on the LOCK button, the scripts below re-protecting all the worksheets.
ActiveWorkbook.Protect Password:="password"
Sheets("1 - TRAINING").Protect "password"
ActiveSheet.Range("1 - TRAINING").Range("K6:U3175").Locked = False
I get the error in the code to unlock the range. How can I unprotect just that range of cells?
Upvotes: 0
Views: 357
Reputation: 73
You'll want to follow the order of events provided by Gary's answer. In code, this'll look like
With ThisWorkbook.Worksheet(1)
.Unprotect "1234" 'insert your pasword here (1)
.Range("A:B").Cells.Locked = False '(2)
.Protect "1234" 'insert your pasword here (3)
End With
Upvotes: 1
Reputation: 96753
In the following order:
Upvotes: 1