Home » excel » How to Unsort the Sorted data ( Excel VBA)

How to Unsort the Sorted data ( Excel VBA)

Posted by: admin May 14, 2020 Leave a comment


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?


How to&Answers:

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.


I am not sure how to do it using VBA coding. However, you’ve two options provided you haven’t saved changes, if any:

  1. 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.
  2. 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.


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.


This is something I had to resolve of late as well. This is how I did it.

  1. Create a temporary index (just numbers 1..n) in the last sortcolumn + 1
  2. Include the temporary index column in the sort
  3. Do sorting and processing
  4. Sort using the temporary index
  5. Clear/delete the temporary index column

Hope this helps someone.