Show timestamp when cell is changed
Solution 1:
This VBA code will do it:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wk As Workbook
Set wk = ThisWorkbook
Dim ws As Worksheet
Set ws = ActiveSheet
WatchedColumn = 2
BlockedRow = 1
TimestampColumn = 4
Crow = Target.Row
CColumn = Target.Column
If CColumn = WatchedColumn And Crow > BlockedRow Then
Cells(Crow, TimestampColumn) = Now()
End If
End Sub
You have to copy the code, go to View -> Macros in Excel, Create a new one (any name is valid) and on the left column double click the worksheet where you want to use it (red flag in the picture) and in the right side, paste the code.
This macro modifies the content of the cell on column D whenever theres a change on the same row on column B. The variable BlockedRow protects the first row because it usually has labels, if you have more than one row of labels changed the variable to 2 or more.
If you need to change the columns, make the change on the variables WatchedColumn
and TimestampColumn
. (A=1, B=2, C=3, D=4,... and so on).
Solution 2:
I know there's already an answer, but this VBA is a bit cleaner -
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("B:B")) Is Nothing Then
target.Offset(0, 2) = Now()
End If
End Sub
To adjust for your other requirement not in the question just add an if -
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("B:B")) Is Nothing Then
If target.Row > 1 Then
target.Offset(0, 2) = Now()
End If
End If
End Sub