hello
I am trying to use the below VBA codes, but it seems only one code can be used and dont know how to use multiple VBA codes for the same sheet. The first one is to lock the cell after a value is entered and the second one is writing the date and time when value was entered.
*First*
*Second*
I am trying to use the below VBA codes, but it seems only one code can be used and dont know how to use multiple VBA codes for the same sheet. The first one is to lock the cell after a value is entered and the second one is writing the date and time when value was entered.
*First*
VBA Code:
Dim mRg As Range
Dim mStr As String
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("B:B"), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("B:B"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="Boutiqaat123"
If xRg.Value <> mStr Then xRg.Locked = True
Target.Worksheet.Protect Password:="Boutiqaat123"
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Range("B:B"), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
End Sub
*Second*
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B:B")) Is Nothing Then
With Target(1, 2)
.Value = Date & " " & Time
.EntireColumn.AutoFit
End With
End If
End Sub
Last edited by a moderator: