Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Quick VBA Worksheet Change Event or Selection Question: | Excel Worksheet Functions | |||
Sheet change event and list validation question | Excel Programming | |||
Change Cell from Validated List Not Firing Worksheet Change Event | Excel Programming | |||
change event question | Excel Programming | |||
change event/after update event?? | Excel Programming |