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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to code "undo" event in Excel?

Status
Not open for further replies.

sjh

Programmer
Oct 29, 2001
263
US
Hi,
In my Excel application, I need to iterate some rows and do some calculations. The calculation will be easier if I can sort the rows first and then compute. But after the calculation is done, I would like to "undo" the SORT event and return the worksheet in its original state.

I tried to record the undo event using Macro, but I couldn't. Is there a way? Thank you for your help!
 
Another useful piece of code is:

Application.Repeat ' to undo an undo!

Rgds, John



 
As JWalk points out, undoing VBA ain't easy. Application.Undo won't cut it in most situations.

For what you're tyring to do, you might consider the following approach (I've successfully used it several times in the past):

1) BEFORE you sort, write a temporary index (1 to whatever) in a blank column to the right of your data.
2) Do your sort and perform your calculation.
3) Sort by the index you just created, then clear that column

It's not too hard to code, and it works well.

Hope that helps!

VBAjedi [swords]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top