girishhb
01-27-2014, 08:59 AM
Please combine the below given both the codes so that i can use it in one module.
1. to insert current date and time in A column when data entered 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
2 . To lock the range of cells when data is entered.
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
Thanks in advance for your help
1. to insert current date and time in A column when data entered 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
2 . To lock the range of cells when data is entered.
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
Thanks in advance for your help