Previous value and the new value of a cell.

gpnavin86

New Member
Joined
Aug 28, 2009
Messages
31
Hi,
I am trying to compare the cell value, old with the changed value. I am using the below code to get the new value but I was not able to get the previous value of the cell.
The new value is fetched to the variable z.

Can anyone help please.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
X = Target.Row
y = Target.Column
Z = Cells(X, y).Value
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Not sure what you want you, do you mean something like this?
Code:
[/FONT]
[FONT=Courier New]Sub NEW_OLD_VALUE()
Dim X As String
Dim y As String[/FONT]
[FONT=Courier New]X = ActiveCell.Value
ActiveCell.Value = "5"
y = ActiveCell.Value
MsgBox Application.Sum(X, y)
End Sub[/FONT][FONT=Courier New]
 
Upvote 0
Thanks for your reply.
I will trigger a macro on change of a cell.
If a cell value is changed from 3 to 4, then a macro will get triggered.
I am able to get the cell value as 4 inside the macro.
But i don't know how to get 3(old value of a cell). So that I can compare if it changed from 3 to 4.
 
Upvote 0
That code is working, but it is creating problem because the code is trying to do undo. While undo on a cell it is taking me to another sheet, this is because the the undo is trying to trigger another macro i guess..
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

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