Unprotecting a Range

business_analyst

Board Regular
Joined
Jun 5, 2009
Messages
99
Hello all,

So I have a Userform, which contains a button then when clicked, directs the user to a worksheet where they have to enter information into certain cells. I am trying to protect this worksheet, except for this specific range of cells, which I would like to leave unprotected. I tried using the "Locked" property, but it does not seem to be working.

Code:
Private Sub cmd_02_next_Click()

    Sheets("Distribution").Activate
    Sheets("Distribution").Range("C8:L78").Locked = False
    Sheet15.Protect Password:="test"
    
End Sub
I got that form of code right of the Microsoft website, but it does not seem to work. the protection works, but it protects the entire sheet.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Does this maybe work?

Code:
Private Sub cmd_02_next_Click()

    with Sheets("Distribution")
         .unProtect Password:="test"
         .Range("C8:L78").Locked = False
         .Protect Password:="test"
    end with
    
End Sub
Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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