Get cell's old value on a worksheet change event

zinstall

New Member
Joined
Jan 18, 2008
Messages
3
Hi,

I would like to know how I can get the old value of a cell that has been changed in the moment when the worksheet triggers the change event for this cell.

Thanks a lot!

zinstall
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Like this?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim NewValue, OldValue
    If Target.Address <> "$A$1" Then Exit Sub
    Application.EnableEvents = False
    With Target
        NewValue = .Value
        Application.Undo
        OldValue = .Value
        .Value = NewValue
    End With
    MsgBox "Old Value: " & OldValue & vbCrLf & "New Value: " & NewValue
    Application.EnableEvents = True
End Sub
 
Upvote 0
Thanks,

It's a good way to do it! However I am using a user form to change the content of the cell and so the undo is not working...

Is there another way?
 
Upvote 0
The only thing that I can suggest is to code the UserForm to place the cell's old value on a hidden sheet - kind of like a change tracker. Using Environ("Username"), you could even log who made the change, what time etc...
 
Upvote 0
In that case why not assign the cell's value to a variable before changing it?
Hi,

I've been looking for this answer for a while, Could someone possibly paste a code with the suggested variable before changing it?
 
Upvote 0
I subsequently have found that Application.Undo freqently causes an error. When making changes directly to a cell, you have to capture the old value prior to the Worksheet_Change Event. I store the original value of a cell that is clicked to a Public variable using the Worksheet_SheetSelectionChange event. (OldValue = Target.Value) Works great!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,435
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top