Getting the previous cell value after changing a cell

W

wim hoevenaren

In VB I want to write a script that provides me with the row and column
information of a changed cell.
This can be done with
worksheet_change(ByVal Target as Range)

Target.row and Target.column provides the row and column information of
the changed cell. Target.value provides me with the new updated cell
value.

However, I also want to have the previous cell value of the changed
cell. How can I get this previous cell value?

Regards

wim.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

Tom Ogilvy

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
vVal = Target.Value
Application.Undo
OldValue = Target.Value
Target.Value = vVal
Application.EnableEvents = True
End Sub

an alternate method would be to use a global variable and set it using the
SelectionChange event.
 
T

tur13o

Another trick, but I don't have the code to hand, is to pre-pend the cell's
comment box with the cell's old value each time it changes. Then you can
have a journal of all changes to that cell. You could add a time stamp to
each entry if that's useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top