The code worked well. I have one wrinkle that I need to pursue. I also have
several areas where I need to do the same but where the word "yes" would
trip the changes. In other words answering "yes" in E1 would lock and hide
E2:E4 and answereing "yes" in E6 would lock and hide E7:e10
Could this be incorporated in one subroutine. I tried copying the entire
subroutine and giving it a different name "Private Sub
Worksheet_Change_New(ByVal Target As Range)", but this didn't work.
>I made modifications to volodind's code.
>
[quoted text clipped - 113 lines]
>> >
>> > Dave Peterson
You can't just add new events, so that won't work.
But you add more rules to your code. Since the main idea is pretty much the
same, I figured that just adding more addresses to each of the address variables
would work ok.
But since you're changing the rules (sometimes "no", sometimes "yes"), you'll
have to keep track of that too:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRowsToHide As Variant
Dim myRngToLock As Variant
Dim myCellsToWatch As Variant
Dim WhatToLookFor As Variant
Dim iCtr As Long
Dim DoStuff As Boolean
Dim myPWD As String
myPWD = "hi" '<-- change to the correct password
'one cell at a time
If Target.Cells.Count > 1 Then Exit Sub
myCellsToWatch = Array("f1", "f5", "F8", "f10", "E1", "e6")
myRngToLock = Array("f2:f4", "F6:f7", "F9:F13", _
"f11:f13", "E2:E4", "E7:e10")
myRowsToHide = Array("2:4", "6:7", "9:13", "11:13", "2:4", "7:10")
WhatToLookFor = Array("no", "no", "no", "no", "yes", "yes")
If UBound(myCellsToWatch) <> UBound(myRngToLock) _
Or UBound(myCellsToWatch) <> UBound(myRowsToHide) _
Or UBound(myCellsToWatch) <> UBound(WhatToLookFor) Then
MsgBox "Design Error!"
Exit Sub
End If
DoStuff = False
For iCtr = LBound(myCellsToWatch) To UBound(myCellsToWatch)
If Intersect(Target, Me.Range(myCellsToWatch(iCtr))) Is Nothing Then
'keep looking
Else
DoStuff = True
Exit For
End If
Next iCtr
'not in one of the cells to watch
If DoStuff = False Then Exit Sub
Me.Unprotect Password:=myPWD
Me.Range(myRngToLock(iCtr)).Locked _
= CBool(LCase(Target.Value) = LCase(WhatToLookFor(iCtr)))
Me.Range(myRowsToHide(iCtr)).EntireRow.Hidden _
= CBool(LCase(Target.Value) = LCase(WhatToLookFor(iCtr)))
Me.Protect Password:=myPWD
End Sub
> The code worked well. I have one wrinkle that I need to pursue. I also have
> several areas where I need to do the same but where the word "yes" would
[quoted text clipped - 126 lines]
> >
> > Dave Peterson

Signature
Dave Peterson