Deleting ranges and protecting sheet not working as expected

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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top