PC Review


Reply
Thread Tools Rate Thread

Before Change Event?

 
 
=?Utf-8?B?U3RldmUgQw==?=
Guest
Posts: n/a
 
      7th Sep 2007
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 With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      7th Sep 2007
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

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      7th Sep 2007
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
(E-Mail Removed)
"Steve C" <(E-Mail Removed)> wrote in message
news:CB50F9B4-5A70-495D-BC67-(E-Mail Removed)...
> 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 With Quote
 
=?Utf-8?B?U3RldmUgQw==?=
Guest
Posts: n/a
 
      7th Sep 2007
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
> (E-Mail Removed)
> "Steve C" <(E-Mail Removed)> wrote in message
> news:CB50F9B4-5A70-495D-BC67-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
apply cell change event to single column - WorksheetChange Event MiataDiablo@gmail.com Microsoft Excel Programming 5 4th May 2008 02:28 AM
Problem with CommandBarComboBox Change Event (Event fires only once) M. Khalid Farooq Microsoft Outlook Interoperability 6 23rd Oct 2006 09:44 AM
Control where change event does not trigger click event? =?Utf-8?B?c3dvcmRmaXNo?= Microsoft Powerpoint 2 17th Jul 2006 06:21 PM
MsgBox in Enter event causes combobox not to run Change event =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 0 6th Mar 2006 02:52 PM
Datagrid cell change event? Where to find event. Roger Microsoft VB .NET 4 29th Mar 2005 09:45 PM


Features
 

Advertising
 

Newsgroups
 


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