Solved

Locking/Unlocking Cells Based on Value in Another Cell

Posted on 2013-11-13
2
943 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 51

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

690 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