**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 Decimal Values.

Written by Allen Wyatt (last updated August 15, 2020)**This tip applies to** Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365

Bob often needs to construct tables that are keyed to titles in government regulations. The numbering of the regulations is in decimal form and this creates problems when he tries to sort them in order. Examples are 820.20, 820.25, 820.200, 820.250. Bob enters these as text, but they still come out sorted in a manner that he does not want. In all cases, Excel drops off the trailing zeros and sees "820.20" and "820.200" as the same thing; Bob is wondering what he can do.

First of all, it should be pointed out that if Excel is dropping the trailing zeroes, then the cells are not formatted as text. You'll need to format the cells as text *before* you put anything in them, or else you'll need to precede the entry with an apostrophe. In either case, the trailing zeroes should remain in place.

Another way to force the entries to text is to modify them in some way. For instance, you could enter "Reg 820.200" instead of "820.200." Or you could replace the period after the 820 with a space or a dash. Any of these methods, and many more, would force the entry to be treated as text.

Even if you force the entry of information to text, that still won't solve the sorting problem, however. Sort a bunch of these cells, and they will still come out in an order you don't want:

820.190 820.2 820.20 820.200 820.201 820.25 820.27

The reason is because the sorting is done from left to right, and in this scheme ".20" will always come before ".200" which always comes before ".25." The only way around this is to modify the structure of the numbers so that (in this case) there are always three digits after the decimal point:

820.002 820.020 820.025 820.027 820.190 820.200 820.201

While this gives the proper sorting order, it does havoc to the original intent: to match the numbering used in the governmental numbering system. If you want to be true to that numbering scheme, the only solution is to use three columns for your numbering. The first column would be the government numbers, entered as text. The second column would be the part of those numbers to the left of the decimal point, derived with a formula:

=LEFT(A1,FIND(".",A1)-1)

The third column would be the portion to the right of the decimal point, derived with this formula:

=RIGHT(A1,LEN(A1)-FIND(".",A1))

With the three columns in place, you can then do your sorting based on the contents of the second and third columns. After the numbers are sorted, you can hide the second and third columns, as desired.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (11336) 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 Decimal Values**.

**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!

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

Discover MoreSorting information in a worksheet can be confusing when Excel applies sorting rules of which you are unaware. This is ...

Discover MoreIf you have a mixture of numbers and text in a column and you want to sort based upon that column, the results may not be ...

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

2020-08-15 15:34:04

Chris Lefsrud

=IF(ISBLANK(A2),"",TEXT(LEFT(A2,FIND(".",A2,1)-1),"000")&"."&TEXT(RIGHT(A2,LEN(A2)-FIND(".",A2,1)),"000"))

A formula approach does not care if the values in the source column are text or numeric. This example pads out each of the two segments (before and after the decimal) to a minimum of 3 digits.

Then just protect this column to prevent overwriting the formula, and use it for the sort operation.

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