by Allen Wyatt
(last updated September 12, 2020)
Vitalis has a column that contains serial numbers. These are formatted such as SFP/0002/2015, SFP/0234/2017, etc., where the final four digits are a year. He needs to sort these serial numbers by year, then by the leading characters. He wonders about the easiest way to do this.
The tried-and-true traditional way to approach this task is to use a helper column to contain what you want as your primary sort key. For instance, let's say that your serial numbers are in column A, with the first one in cell A2. You could place the following formula in cell B2:
What you end up with is just the year in cell B2. Copy this formula down as many rows as necessary, and then do a traditional sort using the Sort tool on the Data tab of the ribbon. You will want the primary sort to be based on column B and the secondary sort to be based on column A. You can then hide the helper column if you don't want it visible or delete it completely if you won't need to do any additional sorting.
If you are using Office 365, there are some new capabilities that were added to Excel that you may find helpful when it comes to sorting. One of the new functions added (SORTBY) allows you to sort a range of cells quite easily, without the need to use the actual Sort tool available on the Data tab of the ribbon.
Let's say, for instance, that your serial numbers are in the range A2:A1000. You could use the following formula to sort them:
Use this formula, again, in a helper column, and the column will contain the sorted values from A2:A1000. The first parameter supplied to the SORTBY function is the range of cells you want to sort, and the second is the range by which you want them sorted. In this case, that second parameter is an array of values that puts the year first followed by the leading characters of each serial number.
One side benefit of using SORTBY is that your original serial numbers are not positionally changed at all. The helper column contains the sorted serial numbers, so you end up with both lists—sorted and unsorted—in your worksheet.
Remember, again, that the SORTBY function is available only in the version of Excel provided with Office 365. If you will be sharing your workbook with someone using an earlier version of the program, then you'll want to either remove the SORTBY function (by using Paste Values on the sorted values in the helper column) or just rely on the traditional approach discussed earlier.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7971) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
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
Government and industrial organizations often use a numbering system that relies upon a number both before and after a ...Discover More
Sorting is one of the basic operations done in a worksheet. If your sorting won't work and you instead get an error ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.