The code below represents change actions for a spreadsheet I am using. The issue I am having is that I originally locked the sheet with a password however once these worksheet changes happen the sheet will lock and unlock but its not password protected.
I always want the sheet to be password protected after the IF ELSE changes happen.
I am not sure of the proper code or where to embed the code and sheet password.
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
If Range("B22") = "Select From Drop Down" Then
Range("B24:B29").Locked = True
Range("B30:B32").Locked = True
Range("B34").Locked = True
ElseIf Range("B22") = "Yes" Then
Range("B24:B29").Locked = True
Range("B30:B32").Locked = False
Range("B34").Locked = False
Else
Range("B24:B32").Locked = False
Range("B34").Locked = False
End If
If Range("B44") = "Select From Drop Down" Then
Range("B46:B54").Locked = True
ElseIf Range("B44") = "Yes" Then
Range("B46:B51").Locked = True
Range("B52:B54").Locked = False
Else
Range("B46:B54").Locked = False
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Bookmarks