title: Excel VBA timestamp and username
body: <p>The code below detects data when inputted into column A and automatically inserts the current user into the cell to the right. I would also like this code to add a timestamp as well. I need to log the user name and time. Any suggestions? </p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Excel.Range)
      Dim rCell As Range
      Dim rChange As Range
  
      On Error GoTo ErrHandler
      Set rChange = Intersect(Target, Range("A:A"))
      If Not rChange Is Nothing Then
          Application.EnableEvents = False
          For Each rCell In rChange
              If rCell &gt; "" Then
                  With rCell.Offset(0, 1)
                      .Value = UserName()
  
                  End With
  
              Else
                  rCell.Offset(0, 1).Clear
              End If
          Next
      End If
  
  ExitHandler:
      Set rCell = Nothing
      Set rChange = Nothing
      Application.EnableEvents = True
      Exit Sub
  ErrHandler:
      MsgBox Err.Description
      Resume ExitHandler
  End Sub
  
  Public Function UserName()
      UserName = Environ$("UserName")
  End Function
  </code></pre>