I’m now sorting some data using a VBA code. ( for some search feature)
After my search is complete I would like to unsort the data back into its original form.
How do I do that?
Thanks.
Just make a copy of the data before sort and set it back..
Other way: you need preserve keys before sort (with hash map) and resort array (after main sort) again by those keys.
Answer:
I am not sure how to do it using VBA coding. However, you’ve two options provided you haven’t saved changes, if any:
- Before sorting add a column with numbers running from 1. Then if you want to restore your sort, you can then sort on this column.
-
In MS Excel 2010 version there is an option to unsort multiple/many columns in excel in one go:
HOME->EDITING->SORT &FILTER drop down menu->CLEAR.
This will clear all the columns/rows in the that Worksheet.
Answer:
Ctrl+Z undoes the action if you have not saved it. Another option is to create another sheet and paste the data in there to use as a backup.
Answer:
This is something I had to resolve of late as well. This is how I did it.
- Create a temporary index (just numbers 1..n) in the last sortcolumn + 1
- Include the temporary index column in the sort
- Do sorting and processing
- Sort using the temporary index
- Clear/delete the temporary index column
Hope this helps someone.
Tags: excelexcel, vba