In excel, I need to know who the last user was that edited a particular cell with their name to populate?
Just watched your video on Time and Date automation with VBA and thought this was also possible?
In excel, I need to know who the last user was that edited a particular cell with their name to populate?
Just watched your video on Time and Date automation with VBA and thought this was also possible?
If you want to get the user's name, as listed in Excel, you use this:
Application.UserName
To add it to the macro for the Automatic Timestamping, you could put this code at the bottom of the macro, before End Sub
'Update cell with username - 7 = Column G
Cells(Target.Row, 7).Value = Application.UserName
Change the 7 to the number of the column where you want the user name to go; 1 is A; 2 is B; and so on.
Full macro code based on your comment:
Private Sub Worksheet_Change(ByVal Target As Range)
'Timestamp Data
' TeachExcel.com
Dim myTableRange As Range
Dim myDateTimeRange As Range
Dim myUpdatedRange As Range
'Your data table range
Set myTableRange = Range("A2:J1500")
'Check if the changed cell is in the data tabe or not.
If Intersect(Target, myTableRange) Is Nothing Then Exit Sub
'Column for the date/time
Set myDateTimeRange = Range("E" & Target.Row)
'Column for last updated date/time
Set myUpdatedRange = Range("F" & Target.Row)
'Stop events from running
Application.EnableEvents = False
'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
'Update cell with username - 1 = Column A; 2 = Column B; etc.
Cells(Target.Row, 17).Value = Application.UserName
'Turn events back on
Application.EnableEvents = True
End Sub
Remember to put this code into the worksheet that you want to use it on.
Also, test this code on a sample sheet first to make sure it works like you want.