Hello; i would like to lock all cells in an excel sheet after a first data input
i use the code

ActiveSheet.Unprotect Password:="YourPassword"
Target.Locked = True
ActiveSheet.Protect Password:="YourPassword"

normally it should work fine

but in that same sheet i had an other code who allow me put in order lines according the number i enter in cell on culumn A
the used code for that is

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A1").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub

so the problem is thta these two codes don't work together
it gave me an error message when i click in some cell

my question :
how can i use both these codes at the same sheet because i need them both

thanks