Protect sheet using following vba code with "do not select locked cells"?

its not work when i open the work book then "do not select locked cell" is not work but when i enter the data on target cell then its work perfectly and some time the all vba code has not work.i use excel 2007. Any can solve this? Option Explicit Private... show more its not work when i open the work book then "do not select locked cell" is not work but when i enter the data on target cell then its work perfectly and some time the all vba code has not work.i use excel 2007.
Any can solve this?



Option Explicit

Private Sub WORKSHEET_CHANGE(ByVal TARGET As Range)
Dim wsSD As Worksheet
Dim wsS As Worksheet
Set wsSD = Sheets("DATA")
Set wsS = Sheets("STCC")
If TARGET.Address = "$L$171" Then
Sheets("STCC").Unprotect Password:="password"
wsS.Range("L172").Value = ""
wsSD.Range("Database").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=wsS.Range("L170:L171"), _
CopyToRange:=wsS.Range("AC110"), Unique:=True
ActiveSheet.EnableSelection = xlUnlockedCells
Sheets("STCC").Protect DrawingObjects:=True, CONTENTS:=True, Scenarios:=True, Password:="password"

End If
End Sub
1 answer