Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

protecting cells

ResolvedVersion 2010

Maia has attended:
O365 Digital Champions course
Excel Power Query course
Excel Intermediate course

Protecting cells

How can you protect a range of cells based on an answer that is selected in a cell?

RE: Protecting cells

Hi Maia,

I hope the following will help:

Copy the code below, right-click a sheet tab, select View Code, then paste the code below into the code window which opens. Create a drop-down in cell B3 with Promote and Demote as options. The code below will lock cells C3 to C10 if you select Promote, while nothing will happen if you select Demote. The password to unprotect is PASSWORD. You can change bits of the code to suit your needs.

Private Sub Worksheet_Change(ByVal Target As Range)
If [B3] = "Promotion" Then
ActiveSheet.Unprotect ("PASSWORD")
[c3:c10].Locked = True
ActiveSheet.Protect ("PASSWORD")
'Remove locked property if B3's value is anything else or is deleted.
ElseIf [B3] = "Demotion" Then
ActiveSheet.Unprotect ("PASSWORD")
[c3:c10].Locked = False
'Optional, reprotect sheet
'ActiveSheet.Protect ("PASSWORD")
End If
End Sub

Kind regards
Marius Barnard
Excel Trainer

Wed 16 Dec 2015: Automatically marked as resolved.

Excel tip:

Paste with Live Preview in Excel 2010

Did you know you can preview what you are about to paste? Here's how to do it.

Copy what you are about to paste
Position the cursor where you want to paste
Right click to display the shortcut menu
Place the cursor over the Paste Options and this will give you a preview of the what you are about to paste.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.