The code locks the cells correctly. You need to protect the sheet for the lock to come into effect, though.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim tValue As Integer
If Target = Range("B1") Then
If Not IsNumeric(Target.Value) Then
MsgBox "Not a valid value"
Else
ActiveSheet.Unprotect Password:="secret"
tValue = Target.Value + 2
Range("B3" & tValue, "B1003").Locked = False
Range("B3", "B" & tValue).Locked = True
ActiveSheet.Protect Password:="secret"
End If
End If
End Sub
If you don't want to set a password, just remove the parameter from the Unprotect and Protect statements.