Hi all,
I have found this code for a timestamp, which I have pasted in VBA under the applicable worksheet (which I believe is the correct spot?).
Column C has an IF formula that returns a TRUE or FALSE. The answer always starts out FALSE.
The code is supposed to look for changes to cells in column C (i.e. switch from FALSE to TRUE), and if column D is blank, then add a timestamp in D (so that only the time of the "first" change to column C is timestamped).
The code satisfies the "first" timestamp only, but it seems to put in this timestamp every time the IF formula calculates (even if the solution recalculates and returns FALSE) - but I only want the timestamp to occur if the IF formula returns TRUE (I want the timestamp to remain if there is a change from FALSE -> TRUE -> FALSE)
Can you please help tweak the code? Thanks
I have found this code for a timestamp, which I have pasted in VBA under the applicable worksheet (which I believe is the correct spot?).
Column C has an IF formula that returns a TRUE or FALSE. The answer always starts out FALSE.
The code is supposed to look for changes to cells in column C (i.e. switch from FALSE to TRUE), and if column D is blank, then add a timestamp in D (so that only the time of the "first" change to column C is timestamped).
The code satisfies the "first" timestamp only, but it seems to put in this timestamp every time the IF formula calculates (even if the solution recalculates and returns FALSE) - but I only want the timestamp to occur if the IF formula returns TRUE (I want the timestamp to remain if there is a change from FALSE -> TRUE -> FALSE)
Can you please help tweak the code? Thanks
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20180830
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 3
xTimeColumn = 4
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Now()
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xCellColumn Then
If Cells(xRg.Row, xTimeColumn) = "" Then
Cells(xRg.Row, xTimeColumn) = Now()
End If
End If
Next
End If
End If
End Sub