I have two columns,
- "Date" (Column H)
- "Previous Date in Cell" (Column I)
I would like to use VBA to automatically keep the previous value of "Date" (Column H) and save the value before change in "Previous Date in Cell" (Column I).
Ex. If H2 = 01-06-2018 and the values is changed to 02-06-2018, I2 should than show 01-06-2018 as it is the previous value of the cell.
I would like this code to work for a whole column of cells, not just a single cell. The values in columns H is not manually updated it comes from a formula that looks at a SQL pull out from a third party system. A lot of cells in columns H can therefore be changed simultaneously.
Can you please help me? Thanks in advance.
This is my code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim newVal As Variant
If Target.Count > 1 Then
Exit Sub
End If
If Intersect(Range("H:H"), Target) Is Nothing Then
Exit Sub
End If
Application.EnableEvents = False
Application.ScreenUpdating = False
newVal = Target.Value
Application.Undo
Target.Offset(0, 1).Value = Target.Value
Target.Value = newVal
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub