Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
sai sai is offline
external usenet poster
 
Posts: 10
Default Previous value of cell before change

When a cell value is changed and the worksheet change event is
triggered - is there a way I can get the previous value in the cell
before it was changed?

sai

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Previous value of cell before change

Hi
you could use a static variable to store the previous result. Try something
like
Private Sub Worksheet_Change(ByVal Target As Range)
Static old_value
If Target.Address = "$A$1" Then
MsgBox "Old value: " & old_value
old_value = Target.Value
End If
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany
"sai" schrieb im Newsbeitrag
ups.com...
When a cell value is changed and the worksheet change event is
triggered - is there a way I can get the previous value in the cell
before it was changed?

sai



  #3   Report Post  
Posted to microsoft.public.excel.programming
sai sai is offline
external usenet poster
 
Posts: 1
Default Previous value of cell before change

Frank,

The problem is that it is just not one cell. I have a whole column (and
maybe multiple columns) of numbers for which I will need to know the
previous value. I do not want to carry the same data that is in the
spreadsheet in memory in an array.

The reason I need this is to be able to do a delta. I want to know the
incremental change made - based on which I want to update another cell.

When I use application.undo, the previous value is restored. Is there a way
I can access the undo object (?) to get the previous value?

sai

"Frank Kabel" wrote in message
...
Hi
you could use a static variable to store the previous result. Try

something
like
Private Sub Worksheet_Change(ByVal Target As Range)
Static old_value
If Target.Address = "$A$1" Then
MsgBox "Old value: " & old_value
old_value = Target.Value
End If
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany
"sai" schrieb im Newsbeitrag
ups.com...
When a cell value is changed and the worksheet change event is
triggered - is there a way I can get the previous value in the cell
before it was changed?

sai





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Previous value of cell before change

Private Sub Worksheet_Change(ByVal Target As Range)
Dim OldVal as Variant, NewVal as Variant
if target.count 1 then exit sub
Application.EnableEvents = False
newval = Target.Value
application.Undo
oldval = Target.Value
if isnumeric(OldVal) and isnumeric(NewVal) then
target.offset(0,1).Value = NewVal - OldVal
end if
Target.Value = NewVal
Application.EnableEvents = True
End Sub

You may want to limit the range in which this occurs.

--
Regards,
Tom Ogilvy


"sai" wrote in message
...
Frank,

The problem is that it is just not one cell. I have a whole column (and
maybe multiple columns) of numbers for which I will need to know the
previous value. I do not want to carry the same data that is in the
spreadsheet in memory in an array.

The reason I need this is to be able to do a delta. I want to know the
incremental change made - based on which I want to update another cell.

When I use application.undo, the previous value is restored. Is there a

way
I can access the undo object (?) to get the previous value?

sai

"Frank Kabel" wrote in message
...
Hi
you could use a static variable to store the previous result. Try

something
like
Private Sub Worksheet_Change(ByVal Target As Range)
Static old_value
If Target.Address = "$A$1" Then
MsgBox "Old value: " & old_value
old_value = Target.Value
End If
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany
"sai" schrieb im Newsbeitrag
ups.com...
When a cell value is changed and the worksheet change event is
triggered - is there a way I can get the previous value in the cell
before it was changed?

sai







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
3-Color Scale Vlookup for Current Month/Previous/Pre-Previous NeoFax Excel Discussion (Misc queries) 2 January 8th 10 07:04 PM
How can I recover the previous data after save change due Excel Worksheet Functions 3 July 16th 08 09:11 AM
Can I change column width for remainder but NOT previous text? Amymariebower Excel Discussion (Misc queries) 1 May 23rd 06 11:02 PM
Copied dates automatically change to previous day Suz About this forum 0 February 3rd 06 08:58 PM
change cell shading whenever contents different from previous cell zooeyhallne Excel Discussion (Misc queries) 3 June 6th 05 09:59 PM


All times are GMT +1. The time now is 02:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"