• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Locking cells based on condition of another cell...HELP PLEASE!!!

Rhonda Epps

New Member
I'm setting up a spreadsheet with several rows of data (individual records). I'm trying to lock and turn black columns F, G, and H if the response in column E = "N". I also want to do the same thing to columns J, K, L and M if the response in column I = "N". I need this to happen in EVERY ROW and be set up so that if someone types in one of the cells that should be locked prior to answering the trigger questions in columns E or I, the content of the cells should be deleted.

I hope Im not asking for too much!!! I found a found a thread started by ultros1234 on June 14, 2013 that similar to my issue. that thread include the following code, but since I am an excel idiot I have no idea how to adjust it to accomplish my mission.
Option Explicit

Code:
Sub UnProtectMySheetFirst()
Me.Unprotect Password:=""   'Just in case protection already applied
End Sub

Sub ProtectMySheetLast()
Me.Protect UserInterfaceOnly:=True, Password:=""
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim xRow As Long

UnProtectMySheetFirst

xRow = Target.Row

If Not (Intersect(Target, Range("H3:H1000")) Is Nothing) Then
& #39;changed something in col H
Range(Cells(xRow, "J"), Cells(xRow, "M")).Locked = (UCase(Trim(Cells(xRow, "H").Value)) <> "YES")
End If
& #39;Since it's possible to change both col h and col I, we'll use separate If statements
& #39;rather than an If...else statement
If Not (Intersect(Target, Range("I3:I1000")) Is Nothing) Then
& #39;changed something in col I
Range(Cells(xRow, "N"), Cells(xRow, "P")).Locked = (UCase(Trim(Cells(xRow, "I").Value)) <> "YES")
End If

ProtectMySheetLast

End Sub
 
Last edited by a moderator:
@Rhonda Epps ...
Upload a Sample File to get a quicker responseor
at least
Use [ CODE ] & [ / CODE ] tags to embed your VBA MacrosAs has written in Tip.

because Your case looks like this...

Screen Shot 2017-01-27 at 10.31.23.png
 
vletm

It happens due to forum migration, check this link for further info on this!

http://chandoo.org/forum/threads/upgraded-forums-old-vba-codes-formula-handling.12080/

Code should be..

Code:
Sub UnProtectMySheetFirst()
Me.Unprotect Password:="" 'Just in case protection already applied
End Sub

Sub ProtectMySheetLast()
Me.Protect UserInterfaceOnly:=True, Password:=""
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim xRow As Long

UnProtectMySheetFirst

xRow = Target.Row

If Not (Intersect(Target, Range("H3:H1000")) Is Nothing) Then
'changed something in col H
Range(Cells(xRow, "J"), Cells(xRow, "M")).Locked = (UCase(Trim(Cells(xRow, "H").Value)) <> "YES")
End If
'Since it's possible to change both col h and col I, we'll use separate If statements
'rather than an If...else statement
If Not (Intersect(Target, Range("I3:I1000")) Is Nothing) Then
'changed something in col I
Range(Cells(xRow, "N"), Cells(xRow, "P")).Locked = (UCase(Trim(Cells(xRow, "I").Value)) <> "YES")
End If

ProtectMySheetLast

End Sub

Code updated in original link too.
http://chandoo.org/forum/threads/lock-cells-based-on-a-condition-solved.10685/
 
Last edited:
@Deepak - I just tried to tell this as many times:
Screen Shot 2017-01-27 at 16.23.06.png
... which should follow, if someone would really like to get something ...
 
Back
Top