Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conditional Protection | Excel Discussion (Misc queries) | |||
Conditional Protection question | Excel Worksheet Functions | |||
Conditional Cell Protection | Excel Programming | |||
?Conditional protection | Excel Programming | |||
Conditional protection | Excel Programming |