This question has been asked on SO before, but I am too lazy at the moment to search for it ...
Since the Worksheet_Change
events fires after a cell changes, the Target.Value
will reflect the new value. However, the Undo
command can be used to get the old value by storing the new value into a variable, running the undo, then updating the target with the new value and storing the old value in the desired place.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("G6").Address Then
Application.EnableEvents = False
Dim sOldValue As String, sNewValue As String
sNewValue = Target.Value
Application.Undo
sOldValue = Range("F3").Value
Target.Value = sNewValue
Worksheets("Sheet12").Range("Q3") = sOldValue
Application.EnableEvents = True
End If
End Sub
For multiple cells do this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("G6").Address Then
Application.EnableEvents = False
Dim sOldValue As String, sNewValue As String
sNewValue = Target.Value
Application.Undo
Dim rOld as Range
Set rOld = Range("F3:V3").Value
Target.Value = sNewValue
Range("V8:AD8").Value = rOld.Value
Application.EnableEvents = True
End If
End Sub