LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Conditional Protection

Hi,

Thanks a lot for your help.

Actually it worked very well.

Here's the code I came up with...my solution was a bit more complex
than I presented because I also needed to do the same thing for
January - December with the Y/N value in different cells.

I would appreciate any suggestions on improvements as I am not totally
sure how the error handling works.

Regards,

Robert
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

'Dim Variables
Dim shtPlan1 As Worksheet
Dim shtPlan2 As Worksheet
'Define variables
Set shtPlan1 = Sheets("Plan")
Set shtPlan2 = Sheets("Plan - Interco")

'Conditional protection for Actual months on the forecast pages
Select Case Target.Address

'January section
Case "$B$10"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("J1").EntireColumn.Locked = True
shtPlan2.Range("K1").EntireColumn.Locked = True
Else
shtPlan1.Range("J1").EntireColumn.Locked = False
shtPlan2.Range("K1").EntireColumn.Locked = False
End If

'February section
Case "$B$11"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("K1").EntireColumn.Locked = True
shtPlan2.Range("L1").EntireColumn.Locked = True
Else
shtPlan1.Range("K1").EntireColumn.Locked = False
shtPlan2.Range("L1").EntireColumn.Locked = False
End If

'March section
Case "$B$12"
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("L1").EntireColumn.Locked = True
shtPlan2.Range("M1").EntireColumn.Locked = True
Else
shtPlan1.Range("L1").EntireColumn.Locked = False
shtPlan2.Range("M1").EntireColumn.Locked = False
End If

'April Section
Case "$B$13"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("N1").EntireColumn.Locked = True
shtPlan2.Range("O1").EntireColumn.Locked = True
Else
shtPlan1.Range("N1").EntireColumn.Locked = False
shtPlan2.Range("O1").EntireColumn.Locked = False
End If

'May section
Case "$B$14"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("O1").EntireColumn.Locked = True
shtPlan2.Range("P1").EntireColumn.Locked = True
Else
shtPlan1.Range("O1").EntireColumn.Locked = False
shtPlan2.Range("P1").EntireColumn.Locked = False
End If

'June section
Case "$B$15"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("P1").EntireColumn.Locked = True
shtPlan2.Range("Q1").EntireColumn.Locked = True
Else
shtPlan1.Range("P1").EntireColumn.Locked = False
shtPlan2.Range("Q1").EntireColumn.Locked = False
End If

'July section
Case "$D$10"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("R1").EntireColumn.Locked = True
shtPlan2.Range("S1").EntireColumn.Locked = True
Else
shtPlan1.Range("R1").EntireColumn.Locked = False
shtPlan2.Range("S1").EntireColumn.Locked = False
End If

'August section
Case "$D$11"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("S1").EntireColumn.Locked = True
shtPlan2.Range("T1").EntireColumn.Locked = True
Else
shtPlan1.Range("S1").EntireColumn.Locked = False
shtPlan2.Range("T1").EntireColumn.Locked = False
End If

'September section
Case "$D$12"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("T1").EntireColumn.Locked = True
shtPlan2.Range("U1").EntireColumn.Locked = True
Else
shtPlan1.Range("T1").EntireColumn.Locked = False
shtPlan2.Range("U1").EntireColumn.Locked = False
End If

'October section
Case "$D$13"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("V1").EntireColumn.Locked = True
shtPlan2.Range("W1").EntireColumn.Locked = True
Else
shtPlan1.Range("V1").EntireColumn.Locked = False
shtPlan2.Range("W1").EntireColumn.Locked = False
End If

'November section
Case "$D$14"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("W1").EntireColumn.Locked = True
shtPlan2.Range("X1").EntireColumn.Locked = True
Else
shtPlan1.Range("W1").EntireColumn.Locked = False
shtPlan2.Range("X1").EntireColumn.Locked = False
End If

'December section
Case "$D$15"
'Errorhandling
On Error GoTo ErrorHandler
'Turn screen updating off
Application.ScreenUpdating = False
'Unprotect sheets to update Locked property
shtPlan1.Unprotect
shtPlan2.Unprotect
'Lock or unlock column depending on value
If Target.Value = "Y" Then
shtPlan1.Range("X1").EntireColumn.Locked = True
shtPlan2.Range("Y1").EntireColumn.Locked = True
Else
shtPlan1.Range("X1").EntireColumn.Locked = False
shtPlan2.Range("Y1").EntireColumn.Locked = False
End If

Case Else
'Do nothing
End Select

'Error handling
ErrorExit:
On Error Resume Next
shtPlan1.Protect
shtPlan2.Protect
Set shtPlan1 = Nothing
Set shtPlan2 = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox "An error occurred:" & vbNewLine & _
Err.Description
Resume ErrorExit

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Protection [email protected] Excel Discussion (Misc queries) 1 March 5th 09 05:47 PM
Conditional Protection question [email protected] Excel Worksheet Functions 1 March 5th 09 04:56 PM
Conditional Cell Protection Joe Delaney Excel Programming 1 October 22nd 05 08:45 PM
?Conditional protection yorkeyite[_3_] Excel Programming 3 August 5th 04 11:10 PM
Conditional protection yorkeyite[_2_] Excel Programming 1 August 5th 04 02:44 PM


All times are GMT +1. The time now is 02:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"