Undoing the Effects of a Sort

Written by Allen Wyatt (last updated October 16, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

Nigel randomly entered a few hundred expense slips into a worksheet using the worksheet line number as the reference number for the slip. When he sorted the data by date, the line number is no longer the correct reference number for the slip. (He now knows this was a blunder.) Nigel wonders if it is possible to remove all sorting in a worksheet and return the data to simply the order in which the data records were entered.

The answer to this question is "it depends." What it depends on is when you want to actually remove all the sorting.

For instance, if you sort the data in a worksheet and then don't do anything else, you can press Ctrl+Z to undo the effects of the sort. If, however, you do a bunch of other tasks, then the availability of that Ctrl+Z becomes more and more remote. It becomes completely unavailable if you run a macro (which wipes out the undo stack) or if you exit Excel.

If you want to undo the sorting effects and you have yet to save the Excel workbook on which you are working, you could always close it without saving. When you again open the workbook, the data will still be in the original order, but you will have lost anything you previously did after the sorting and before you closed the workbook.

Finally, if your workbook is saved on either a cloud service (such as OneDrive) or on a company server, it may be possible that you can go back and retrieve a backup version of your workbook. Check out the settings in your cloud service or check with your network administrator to see what is possible in this regard.

The best way to always allow resorting of your data is to make sure you include an "index column." This column would be nothing other than an incremental count of rows: 1, 2, 3, 4, etc. As long as those values aren't based on formulas, you can—at any point—resort your data based on the contents of the column. Your data will then be sorted in its original order.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11314) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

PRIVATE Fields in WordPerfect Documents

Did you ever convert a document from WordPerfect and see PRIVATE fields in it? Here's what those fields mean.

Discover More

Endnotes in a Separate Document

When you add endnotes to a document they are normally positioned (as one would expect) at the end of the document. You ...

Discover More

Automatic Selection of Portrait or Landscape

Should you print in portrait or in landscape? The decision can greatly affect the way your printout looks. Wouldn't it be ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Importing Custom Lists

Custom lists are handy ways to enter recurring data in a worksheet. Here's how you can import your own custom lists from ...

Discover More

Non-standard Sorting

Information in a cell can be entered using line feeds, which results in multiple lines of data in the same cell. If you ...

Discover More

Separating Cells Based on Text Color

If the font color used for the data in your worksheet is critical, you may at some time want to move cells that use a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven minus 7?

2021-10-16 22:55:12

Don White

Hi Allen,
Here in Australia, we are heading into Summer, so snow is far from our minds. We are however heading into bushfire season, so we hope it’s not like 2019-20.
When sorting, I have had a few disasters over the years working with big spreadsheets with university student data. So, I now save my spreadsheets with a date and time before doing a big sort and then continue to save regularly with file name updated. If there are no problems, I can then go back and deleted the progressive files.
Another trap I have fallen into is to find I have only sorted a portion of the data. This can occur due to inserting a new column into the data. If this column has no data entries then it splits the spreadsheet into two separate data ranges… and only works on one of them. To guard against this problem, I have learnt to put in an identifier as the columns at each edge of the spreadsheet. This can be a numeric reference number, but for students, I use their ID number. I then just have to remember to check that these two columns are in sync with each other, which is easy to do using the compare function.


2021-10-16 08:56:01

Roy

In a "by the way" sort of way, one could point out that ANY time one might want to restore a particular order, even though the interim work may delete rows and change values that would not let the original sort parameters place all items in their original order, the helper column with index numbers in it before one sorts for the different purpose/s will, in the end, let you restore to original order for the records.

And if one was adding rows, one could leave that index value untouched as a true null to Excel until after resorting whereupon all the new rows would sort to the absolute bottom. They could then be assigned index numbers of their own, either starting with the next highest, or with the next highest relative to the original highest, if that row got deleted. (The latter would require you to have noted down that original highest number early on, for this purpose, or to be able to learn it any of various ways.)

All in all, the sequential numbering indexing is useful in many ways, though surely, the Tip's, and the above, would be the most commonly occurring.

Caveat: Do NOT rely upon any formula though. Type a 1 in the first cell and insert a sequence, or do a formula, but then Copy it and Paste|Special|Values to lose the formulas. Or you will be in the same boat as Nigel. Slightly different reason/path, but the same boat.


2021-10-16 06:31:56

Alan Bowen

Hi Allen
Here in Cornwall UK the temperature is in the mid teens Celsius so snow is a long way off, I hope. On the sorting issue, I've been caught out by that when I 've used Excel professionally. My solution was to insert a column of sequential numbers at column A starting with 1 at the first line of data. Then if the sort goes wrong you can resort using only that column to get back to where you were originally. Alternatively make a copy of the the worksheet before you sort and delete it as necessary.
Cheers Alan Bowen


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.