Please advise if its possible to insert both the below 2 codes to same sheet(1 to auto update the date when other cell is entered and another is to protect the sheet once data has been inserted. please advise or u merge both the codes and give me. Thanks.
1, protect the sheet when the data is inserted.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:F1048576")) Is Nothing Then 'set your range here
ActiveSheet.Unprotect Password:="mypassword"
Target.Locked = True
ActiveSheet.Protect Password:="mypassword"
End If
End Sub
2. auto update the date and time in A column once the data is updated in B column.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Target.Parent.Range("B:B")
If Target.Count > 1 Then Exit Sub
If Intersect(Target, rng) Is Nothing Then Exit Sub
If Target.Value = "" Then Target.Offset(0, -1).Value = ""
If Target.Value <> "" Then Target.Offset(0, -1).Value = Now
End Sub
Bookmarks