Here's an alternative event procedure that handles the case where the user updates more than one cell at a time (i.e. pastes a block of cells).
When working with the Worksheet_Change
event procedure it is imperative to turn off event handling at the beginning and to make sure it always gets turned back on at the end.
Note that I intentionally left out the formatting of the time stamp as previous examples stripped off the date. If the column is not already formatted and you need to format it, I suggest you add a line of code to set the .NumberFormat
property.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 1 Then
Target.Resize(ColumnSize:=1).Offset(ColumnOffset:=1).Value = Now
End If
Application.EnableEvents = True
End Sub
The case of tracking changes in Column A is easy; other columns can be a bit trickier when users paste blocks of cells. For example, if you want to capture changes to Column D, the code needs to handle the case when cells C2:D2 are pasted in which case Target.Column
= 3. (Use the Intersect
method or also look at the Target.Columns.Count
property.