Protect or unprotect cells depending on option selected

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All:

I have an Excel 2003 file that will be available to several users. One worksheet will be a form for the user to fill in and other worksheets will be hidden. The FORM worksheet will be protected so only cells where the user is to enter data will be unprotected.

My problem is I need to turn on cell protection for some cells depending on the option the user selects. For example, if the user selects option #1, some cells (B2 and B3) will be populated with data by a macro and I want to protect those cells from being changed by the user. If the user selects option #2, those cells should remain unprotected so the user may enter data.

Since the worksheet is already protected (to prevent the user from changing other cells), simply turning on and off worksheet protection won't do the job. I need to be able to leave the worksheet protected but alter which cells are protected.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Can you not use the worksheet change event to test for the value used in the selection box and then alter the properties of the cells you need to with code and then reprotect the sheet?
 
Upvote 0
Something along the lines of this. You have to put this code in the Sheet object in question, not in a Module:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address <> "$B$1" Then Exit Sub

If Range("B1") = "Option 1" Then
'put your unprotect sheet, change formatting of cells to be unlocked, and protect sheet code here. This should be recordable

ElseIf Range("B1") = "Option 2" Then
'put your other unprotect sheet, change formatting of cells to be unlocked, and protect sheet code here. This should be recordable

End If

End Sub

Not sure which form you are using and which linked cell, but i have assumed that when they make a selection the value of B1 changes and depending on what this value is triggers the relevant code. Hope this helps you get closer.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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