Solved

Locking/Unlocking Cells Based on Value in Another Cell

Posted on 2013-11-13
2
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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…
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.

733 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