Background:
I want the macro to automatically record the time and date on the empty cell on right IF the "cell of interest" changes values through a formula.
e.g. IF cell("k3") changes values, THEN register DATE & TIME when it changed on cell ("L3"); IF cell("L3") IS NOT empty, THEN register the TIME & DATE in cell("M3"), and so forth until it finds an empty cell.
So far, I have not been able to prompt the macro whenever the "cell of interest" changes values. PS: the latter is an IF formula that outputs 2 possible strings: "OK" and "ISSUE RISK WARNING"
I have tried the following code:
Private sub Register_timestamp(ByVal Target As Range)
'This sub registers the date and hour at which the cells in column K:K changed values.
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("K:K"))
xOffsetColumn = 1
If WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
xOffsetColumn = xOffsetColumn + 1
End If
Next
Application.EnableEvents = True
End If
End sub
Expected output:
If I were to manually change the cell that is subject to the "cell of interest"'s IF Function - and triggers it -, the date and time at which the "cell of interest" changed, e.g.: 14/05/2019 21:44:21
Here's how you'd implement my suggestions. Make sure this code is on the correct worksheet's code module.