LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Another change event question

Thnaks Otto,

this is clear, but what if the user changed the value of the cell "A1" by
copying and pasting into it the cell "B2", which, in facts, contained not
only a value, but also a comment, some borders, a different number format
and a different font color and type.
Using your code, I'm going to loose everything of that apart the value.
Is there a simple way to store everything of a cell in a variable so that I
can easily re-apply everything from the variable to the cell?
Something like here below, which, I tried, unfortunately put in A2 just the
value of C2 and not also formats, comments, etc.
Dim r As Range
Set r = ActiveSheet.Range("C2")
ActiveSheet.Range("a2") = r

Paolo

--
Paolo
Milan, Italy
NOTE: remove QUESTONO from my email address for direct emailing
"Otto Moehrbach" ha scritto nel messaggio
...
Paolo
Yes, I've used this many times before. No, you cannot reverse the
Undo. The code is something like this:
(Say the cell is A1)
Dim NewValue as Variant
Dim OldValue as Variant
NewValue = Range("A1").Value
Application.Undo
OldValue=Range("A1").Value
'Now you do what you want with your data, then put either OldValue or
NewValue into A1.
'Bracket some of this code with the EnableEvents code as needed. HTH
Otto
"Paolo De Laurentiis" wrote in message
...
Otto,
is this working for you (referring to manually done changes)?
I tried also this, but when the change event happen, I store the new
values, call the Undo, read the previous values, but then I'm unable to
call a Repeat to return to the situation after the changes.
In facts, the code I'm using causes a strange effect since I cannot
Repeat
any action even using the standard Excel button: you see the application
repeating the action, but then the Undo is applied by the macro while the
repeat is not.

Here is the code I'm using.

Application.EnableEvents = False
Call StoreValues(True, True, Wb, Ws, Rng) 'read values after change
Application.Undo
Call StoreValues(False, True, Wb, Ws, Rng) 'read values before change
Application.Repeat
Application.EnableEvents = True

I'm thinking that I can simulate a Repeat writing via macro the new
values
into the cells, since I've stored them, but I'm worried about formats and
comments and whatever the user can have changed in the cells, apart from
the values, with just one single copy and paste operation from the GUI.
Do you think I can use something like:

dim R as Range
set R= Rng 'where Rng is the range where the change happened,
passed
by the SheetChange event
Application.EnableEvents = False
Call StoreValues(True, True, Wb, Ws, Rng) 'read values after change
Application.Undo
Call StoreValues(False, True, Wb, Ws, Rng) 'read values before change
set Rng = R 'so meaning that everything is copied to the worksheet
range: values, formatting, comments, names, etc.
'Application.Repeat
Application.EnableEvents = True

Thanks,
Paolo

--
Paolo
Milan, Italy
NOTE: remove QUESTONO from my email address for direct emailing

"Otto Moehrbach" ha scritto nel messaggio
...
Steph
If the change you are wanting to trap was done manually, you can set
the current (new value) value to a variable, then issue the Undo command
and set the old value to another variable. Then you have both values.
If the change was done by code, then you have to somehow capture the old
value before the change is done. HTH Otto
"Steph" wrote in message
...
Can I somehow capture what the cell value was before it was changed?

I know I can capture the cell changed and the changed value in the
following:
MsgBox "You changed: " & Target.Address & " to " & Target.Value

I would love it to tell me You changed A1 from 15 to 25

Possible?













 
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
Quick VBA Worksheet Change Event or Selection Question: Damil4real Excel Worksheet Functions 6 November 17th 09 10:28 PM
Sheet change event and list validation question Nick Excel Programming 1 October 21st 04 01:20 PM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM
change event question scott23 Excel Programming 3 May 13th 04 01:55 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 01:00 PM.

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"