Solved

Locking/Unlocking Cells Based on Value in Another Cell

Posted on 2013-11-13
2
744 Views
Last Modified: 2014-08-21
I need to unlock a cell based on whether or not another cell in the first cell's row contains a specific value.
Attached is a sample workbook where I need to evaluate range C6:C23 and see if any cells in that range contains (not necessarily equal) the value in cell E3 and if it does then the cells 2 and 3 columns to the right are unlocked for editing.

I would like this code to execute when the worksheet is activated.

Thanks,

Edwin
TestPage001.xlsm
0
Comment
Question by:gixxer1020
2 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39647112
Hi,

Pls insert this code in the worksheet module
Private Sub Worksheet_Activate()
    strPassword = "" ' "pw"
    ActiveSheet.Unprotect Password:=strPassword
    ActiveSheet.Range(Range("C6"), Range("C" & Rows.Count)).Offset(, 2).Resize(, 3).Locked = True
    For Each c In ActiveSheet.Range(Range("C6"), Range("C" & Rows.Count).End(xlUp))
        If c.Value Like "*" & Range("E3").Value & "*" Then
            c.Offset(, 2).Resize(, 3).Locked = False
        End If

    Next
    ActiveSheet.Protect Password:=strPassword, UserInterfaceOnly:=True
End Sub

Open in new window

0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39647649
I have got round similar issues by using custom Data Validation.

You can use a formula to validate an entry into a cell.

When the check on the other cell is verified to disable entry (Lock cell) set the validation rule such that the entry is impossible to be valid eg if numerical entry >0 AND <0, the entry can't be both so will be rejected; if text "contains 200 z's" although not impossible is unlikely.

When the check on the other cell is verified and will allow entry then you can set the validation to be anything.

Thanks
Rob H
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

765 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