poolarajesh
New Member
- Joined
- Feb 13, 2014
- Messages
- 1
Hello guys,
I have used below code to delete ranges and create ranges and then protect sheets. For one sheet (Scorer) it is working perfectly but for second sheet (Instructions) it is giving Protection error when I clicked on C2 cell. Please let me know if I am doing anything wrong here?
Sub Clear_button()
UnprotectSheet SN:="Scorer"
ProtectRange = "C1:C6, B10:B11"
Call protectSheet(ProtectRange, "Scorer", "Scorrng")
Sheets("Library").Visible = xlSheetVeryHidden
UnprotectSheet SN:="Instructions"
ProtectRange = "C2"
Call protectSheet(ProtectRange, "Instructions", "Instrng")
Range("C2") = ""
End Sub
Sub UnprotectSheet(ByVal SN As String)
Sheets(SN).Unprotect Password:="ABCDEF*1"
End Sub
Sub protectSheet(PR, SN, rng)
Sheets(SN).Protection.AllowEditRanges(rng).Delete
Sheets(SN).Protection.AllowEditRanges.Add Title:=rng, Range:=Range(PR)
Sheets(SN).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="ABCDEF*1"
End Sub
I have used below code to delete ranges and create ranges and then protect sheets. For one sheet (Scorer) it is working perfectly but for second sheet (Instructions) it is giving Protection error when I clicked on C2 cell. Please let me know if I am doing anything wrong here?
Sub Clear_button()
UnprotectSheet SN:="Scorer"
ProtectRange = "C1:C6, B10:B11"
Call protectSheet(ProtectRange, "Scorer", "Scorrng")
Sheets("Library").Visible = xlSheetVeryHidden
UnprotectSheet SN:="Instructions"
ProtectRange = "C2"
Call protectSheet(ProtectRange, "Instructions", "Instrng")
Range("C2") = ""
End Sub
Sub UnprotectSheet(ByVal SN As String)
Sheets(SN).Unprotect Password:="ABCDEF*1"
End Sub
Sub protectSheet(PR, SN, rng)
Sheets(SN).Protection.AllowEditRanges(rng).Delete
Sheets(SN).Protection.AllowEditRanges.Add Title:=rng, Range:=Range(PR)
Sheets(SN).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="ABCDEF*1"
End Sub