Hello there,
When I run this code excel crashes.
Task: Cell F42 has drop down options YES/NO
If F42=Yes, unprotect sheet, unlock cell K42 (merged with L42), protect sheet
If F42=No or empty, unprotect sheet, unlock cell K42:L42, clear contents of K42:L42, lock cell K42:L42, protect sheet
Main reasoning behind second step is if selection from F42 cleared, I need K42:L42 to be cleared as well and protected.
I have this code, if works fine for "Yes" portion, but once I select "No" or clear the contents of F42, Excel crashes :
Thanks!
When I run this code excel crashes.
Task: Cell F42 has drop down options YES/NO
If F42=Yes, unprotect sheet, unlock cell K42 (merged with L42), protect sheet
If F42=No or empty, unprotect sheet, unlock cell K42:L42, clear contents of K42:L42, lock cell K42:L42, protect sheet
Main reasoning behind second step is if selection from F42 cleared, I need K42:L42 to be cleared as well and protected.
I have this code, if works fine for "Yes" portion, but once I select "No" or clear the contents of F42, Excel crashes :
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("F42") = "Yes" Then
ActiveSheet.Unprotect "Password1"
Range("K42:L42").Locked = False
ActiveSheet.Protect "Password1"
Else
If Range("F42") <> "Yes" Then
ActiveSheet.Unprotect "Password1"
Range("K42:L42").Select
Selection.ClearContents
Else
Range("K42:L42").Locked = True
ActiveSheet.Protect "Password1"
End If
End If
End Sub
Thanks!