Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Sorting while Ignoring Leading Characters.
Written by Allen Wyatt (last updated December 6, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Ritesh has a huge amount of data that he needs to process in Excel. Each line in a worksheet includes a part number, in column A, by which he needs to sort the records. The problem is that Ritesh cannot do a straight sort; the first four characters of the part numbers need to be ignored. Thus, the sorting actually needs to start with the fifth character of the part number.
The easiest way to handle this situation is to create a new column in Excel that consists entirely of the information you want to use in the sort. In this case, you could add a new, blank column to the right of column A, and then enter this formula in the first cell of the column (assumed to be cell B2):
=RIGHT(A2,LEN(A2)-4)
You'll notice that cell B2 now contains the part number, beginning with the fifth character. Copy this formula down as many cells as necessary, and then perform a standard sort based on the contents of column B.
Another way to come up with the new column—if you are using Excel 2013 or later—is to use the Flash Fill feature. Personally, I find this a bit more restrictive than using the formula already mentioned, but it may work just fine for your needs. All you need to do in cell B2 is to type the portion of cell A2 that you want to use. For instance, if cell A2 contains the part number "ABCDU643," in cell B2 you would type "U643". Then, with cell B2 selected, right-click the fill handle and drag it downward for as many cells as necessary. When you release the mouse button, you'll see a Context menu appear from which you can choose Flash Fill.
I mentioned that I find Flash Fill a bit restrictive because it doesn't always make the proper determination of how the cells should be derived from the originals. For instance, let's say that cell A2 contains "ABCD1234" and that you type "1234" into cell B2. Further, cell A3 contains "EFGHA567". When you Flash Fill based on cell B2, then Excel makes the determination that you want to remove all the letters from the beginning of the other cells, so that B3 ends up containing "567" instead of "A567", as you really wanted. This misinterpretation on the part of Excel only occurs if the first cell (B2) contains only digits.
Regardless of how you get the significant portion of your part numbers into column B, when you perform the sort based on the contents of column B, you'll end up with your part numbers in the desired order. You can then either delete column B, or you can hide it if you may need it later but don't want it to show up.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9870) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Sorting while Ignoring Leading Characters.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
When you sort data that contains both numbers and text, you may not get exactly the result that you expected. To know ...
Discover MoreSorting by dates is easy, and you end up with a list that is in chronological order. However, things become a bit more ...
Discover MoreIf you use graphics in a worksheet that are associated with certain cells (perhaps images of parts or icons for worksheet ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-12-08 14:04:05
J. Woolley
The TrimHead function would be useful in this case. It is described in my comment here: https://excelribbon.tips.net/T009746_Replacing_Characters_at_the_End_of_a_Cell.html
2023-12-07 05:53:08
Peter
I think that you could you use power query to generate a sorted list in another tab. Something like split column A, sort on column A.2, combine A.1 and A.2
2023-12-06 10:52:11
Don Small
In the interest of the KISS principle (Keep It Sweet & Simple), instead of =RIGHT(A2,LEN(A2)-4), I recommend =MID(A2,4,999).
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments