Excel Conditional Cell Protection

Posted on 2010-08-23
Last Modified: 2012-06-27
I have a spreadsheet with rows which users need to edit before final approval but not afterward.  I need some help with conditional protection.  Basically, in the attached spreadsheet, if L5 is <> null, I need entire row 5 protected.  If L5 = null, then the row should be open for editing.  And then this same criteria applied to the remainder of the spreadsheet, with the L column from cell 5 onward as the key.  Can anyone help?
Question by:mrherndon
  • 4
  • 3
LVL 24

Expert Comment

ID: 33505209
Your sheet is password protected.  Unprotect and re-post.

Author Comment

ID: 33505277
Apologies.  Unprotected.
LVL 24

Accepted Solution

broomee9 earned 500 total points
ID: 33505360
OK, try this:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errHandler

    Application.EnableEvents = False

    If Target.Column = 12 And Target.Count = 1 Then
        Call UnProtect
        If Target.Value <> "" Then Rows(Target.Row).Locked = True
        Call Protect
    End If

    Application.EnableEvents = True
    Exit Sub

    MsgBox Err.Number & " - " & Err.Description
    Resume finished

End Sub

Open in new window

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.


Author Comment

ID: 33505583
Thanks.  It works great on the "test" line.  But the rest of the sheet is unaffected.  What am I missing?
LVL 24

Expert Comment

ID: 33506400
The values are already filled in.  This code is triggered when you enter a new value in column L.  So either protect the cells now for each line that already has a value, or remove the initials and then re-add them back in and the code will execute for each one.

Author Comment

ID: 33506605
I see.  So, going forward it will lock new data.  Existing data I can manually lock.  Do I understand you correctly?
LVL 24

Expert Comment

ID: 33521099
Yes, that's correct.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
After updating data my Excel graphs are showing too many dates 8 33
Freeze Panes Solution 6 28
macro for closing opened workbook 6 21
Excel sheet question 12 29
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now