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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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