?
Solved

Locking/Unlocking Cells Based on Value in Another Cell

Posted on 2013-11-13
2
Medium Priority
?
1,374 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 54

Accepted Solution

by:
Rgonzo1971 earned 2000 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 34

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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

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…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

850 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