Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Before Change Event?

Does Excel have a BEFORE change event in a worksheet? I'd like to capture
the value of a cell before it was changed in addition to what it was changed
to.

I understand that in the Private Sub Worksheet_Change(ByVal Target As Range)
procedure, Target.Address and Target.Value can be used to identify what cell
was changed and what value it was changed to, but it would be useful to know
what the original cell value was. Thanks!
--
Steve C
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Before Change Event?

You need to create a global variable to hold the value and then use the
selection change and sheet activate events to capture the value prior to it
being changed...

Private m_varMyValue As Variant

Private Sub Worksheet_Activate()
m_varMyValue = Range("A1").Value
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
m_varMyValue = Range("A1").Value
End Sub

You may also want to capture the value when the spreadsheet is opened. If so
then use the event code in thisworkbook to populate the variable (which will
need to be changed to public)...

--
HTH...

Jim Thomlinson


"Steve C" wrote:

Does Excel have a BEFORE change event in a worksheet? I'd like to capture
the value of a cell before it was changed in addition to what it was changed
to.

I understand that in the Private Sub Worksheet_Change(ByVal Target As Range)
procedure, Target.Address and Target.Value can be used to identify what cell
was changed and what value it was changed to, but it would be useful to know
what the original cell value was. Thanks!
--
Steve C

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Before Change Event?

Option Explicit
Dim oldvalue As Double

Private Sub Worksheet_Change(ByVal target As Excel.Range)
If target.Address = "$A$5" Then
On Error GoTo fixit
Application.EnableEvents = False
If target.Value = 0 Then oldvalue = 0
target.Value = 1 * target.Value + oldvalue
MsgBox oldvalue
oldvalue = target.Value
fixit:
Application.EnableEvents = True
End If
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Steve C" wrote in message
...
Does Excel have a BEFORE change event in a worksheet? I'd like to capture
the value of a cell before it was changed in addition to what it was
changed
to.

I understand that in the Private Sub Worksheet_Change(ByVal Target As
Range)
procedure, Target.Address and Target.Value can be used to identify what
cell
was changed and what value it was changed to, but it would be useful to
know
what the original cell value was. Thanks!
--
Steve C


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Before Change Event?

Thank you both for the help!
--
Steve C


"Don Guillett" wrote:

Option Explicit
Dim oldvalue As Double

Private Sub Worksheet_Change(ByVal target As Excel.Range)
If target.Address = "$A$5" Then
On Error GoTo fixit
Application.EnableEvents = False
If target.Value = 0 Then oldvalue = 0
target.Value = 1 * target.Value + oldvalue
MsgBox oldvalue
oldvalue = target.Value
fixit:
Application.EnableEvents = True
End If
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Steve C" wrote in message
...
Does Excel have a BEFORE change event in a worksheet? I'd like to capture
the value of a cell before it was changed in addition to what it was
changed
to.

I understand that in the Private Sub Worksheet_Change(ByVal Target As
Range)
procedure, Target.Address and Target.Value can be used to identify what
cell
was changed and what value it was changed to, but it would be useful to
know
what the original cell value was. Thanks!
--
Steve C



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
How do I change a Worksheet_change event to a beforesave event? Tueanker Excel Programming 5 June 29th 07 03:00 PM
MsgBox in Enter event causes combobox not to run Change event Richard Excel Programming 0 March 6th 06 02:52 PM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM


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

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

About Us

"It's about Microsoft Excel"