Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

undo a macro? 1

Status
Not open for further replies.

venkman

Programmer
Oct 9, 2001
467
US
I had do a lot manual stuff with a sheet that included pasting by value ("paste special..." -> "value"). So being the lazy pos I am, I wrote a macro that does paste by value and made a custom button for it.... that way it only requires 2 clicks to do rather than 4 (1.right click cell, 2. click "paste special..." 3 and 4. double click "value"). However, now that I've done this as a macro, I can't undo when I make a mistake. Is there anyway to implement undo for a macro. Or at the very least can I write another macro which can reverse the effects of running this macro:

Sub pasteValue()
Selection.PasteSpecial Paste:=xlValues, _
operation:=xlNone, SkipBlanks:= False, Transpose:=False

End Sub

-Venkman
 
You need to use the application.OnUndo property. Your sub needs to save the original of the modified range in a temporary location (personal.xls might work), along with any information needed to reconstruct the original worksheet (probably the range.address for your range).
Then you need to have an Undo sub which reverses the action. Not too difficult, in your case.
Rob
 
Here's a much simpler answer - instead of a custom paste special values, use the button provided
Goto View>Toolbars>Customize
Choose the Edit toolbar
Scroll down using the scroll bar till you get to the "Paste Values" button (looks like a clipboard with a 12 on it)
drag and drop this onto your toolbar
Voila, a paste special values button that you can undo in the normal fashion Rgds
~Geoff~
 
sounds like too much effort just to be lazy. I'll take my chances without an undo. Thanks for the reply though.
-Venkman
 
sorry, my previous reply was to first response. xlbo, you d'man, exactly what I was looking for.
-Venkman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top