The code below will add the user's name in column G.
Private Sub Worksheet_Change(ByVal Target As Range)
'Timestamp Data
' TeachExcel.com
Dim myTableRange As Range
Dim myDateTimeRange As Range
Dim myUpdatedRange As Range
Dim myUserRange As Range
'Your data table range
Set myTableRange = Range("A2:D50")
'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("E" & Target.Row)
'Column for last updated date/time
Set myUpdatedRange = Range("F" & Target.Row)
'Column for user executing last update
Set myUserRange = Range("G" & Target.Row)
'Determine if the input date/time should change
If myDateTimeRange.Value = "" Then
myDateTimeRange.Value = Now
Else
'Update the updated date/time value
myUpdatedRange.Value = Now
End If
myUserRange.Value = Application.UserName
'Turn events back on
Application.EnableEvents = True
End Sub
Please note that the code will write the time in column E, if that field is blank. It will write in column F if the E isn't blank. This means that column F will be over-written if more than one update is made. The code will write in column G every time and update is made, meaning any existing name will be over-written on every change.
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