Protect / Unprotect Worksheet
Hi,
Here is the three separate macros.
One that provides the status in A1,
One to lock but leave ranges unlocked and
An unlock
The password is set as PASSWORD by default, although to utilise the unlock password you will need to use an input box
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect "PASSWORD"
Range("A1").Value = "PROTECTED"
ActiveSheet.Protect "PASSWORD"
Else
Range("A1").Value = "NOT PROTECTED"
End If
End Sub
Sub LockSheetCells()
Sheets("Time").Unprotect "PASSWORD"
Sheets("Time").Cells.Locked = True
Sheets("Time").Range("C10:C20, C36:M42, C10:C20, C36").Locked = False
Sheets("Time").Protect "PASSWORD"
Sheets("REPORT").Unprotect "PASSWORD"
Sheets("REPORT").Cells.Locked = True
Sheets("REPORT").Range("C8").Locked = False
Sheets("REPORT").Protect "PASSWORD"
End Sub
Sub UnlockSheets()
Sheets("Time").Unprotect "PASSWORD"
Sheets("REPORT").Unprotect "PASSWORD"
End Sub
Thanks & Regards,
Anurag Kohli
- anuragkin's blog
- Login or register to post comments
- 3268 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago