Hi all,
I would like to combine two worksheet VBA codes.
The first code creates a timestamp and username of the last person to update any cell in the table, while the second code lock cells in the worksheet after data is entered into them.
See code one below
See Code Two Below
I want the two codes to run as one, Thanks as always.
I would like to combine two worksheet VBA codes.
The first code creates a timestamp and username of the last person to update any cell in the table, while the second code lock cells in the worksheet after data is entered into them.
See code one below
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myTableRange As Range
Dim myDateTimeRange As Range
Dim myUpdatedRange As Range
'Your data table range
Set myTableRange = Range("A2:R1000000")
'Check if the changed cell is in the data tabe or not.
If Intersect(Target, myTableRange) Is Nothing Then Exit Sub
'Stop events from running
Application.EnableEvents = False
'Column for the date/time
Set myDateTimeRange = Range("U" & Target.Row)
'Column for last updated date/time
Set myUpdatedRange = Range("V" & Target.Row)
'Determine if the input date/time should change
If myDateTimeRange.Value = "" Then
myDateTimeRange.Value = Now
End If
'Update the updated date/time value
myUpdatedRange.Value = Now
myUpdatedRange.Offset(, 1).Value = Application.UserName
'Turn events back on
Application.EnableEvents = True
End Sub
See Code Two Below
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Unprotect "123"
If VBA.IsEmpty(Target) Then
Target.Locked = False
Else
Target.Locked = True
End If
Sheet2.Protect "123"
End Sub
I want the two codes to run as one, Thanks as always.