Numeric Sort with Trailing Zeros

Gsrgofass

New Member
Joined
Nov 8, 2019
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a serial number column in my database where the leading and last number of the 6 digit number represents the YOM (year of manufacture) of the machine. I have it formatted as 'Special' in order to display a leading zero for 2020 models.
When doing a general search for a range of serial numbers choosing 'Smallest to Largest' is a popular choice.
Ex:
019742 (2020 YOM)
793821 (2017 YOM)
803061 (2018 YOM)
915471 (2019 YOM)

If I sort 'Smallest to Largest', I get the order as you see above. 2020 listed prior to any other year. When 2021 hits, I will have years 2019 and then see 2021 serial number with 2020 still at the top of the list.

Is it possible to sort but have the leading 0 come after a leading 9 and then allow the next leading number to be a 1, 2.... and so on?
793821 (2017 YOM)
803061 (2018 YOM)
915471 (2019 YOM)
019742 (2020 YOM)
115202 (2021 YOM)
213302 (2022 YOM)
etc....
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Are you going to be doing the sort manually or will it be done by a macro?

In the example so far, the earliest year is 2017 and the latest 2022 but what will be the absolute earliest and latest years to sort?
 
Upvote 0
One way would be to extract the year part in another column with a formula, and use this new column as your Primary sort field, and then your values above as your Secondary sort field.
 
Upvote 0
Are you going to be doing the sort manually or will it be done by a macro?

In the example so far, the earliest year is 2017 and the latest 2022 but what will be the absolute earliest and latest years to sort?
Sort in manual. The earliest year in the database is 2013 and I would like to keep all the data in one sheet, if possible.
This database will continue to grow as the years go on so the latest year will continue to increase.
 
Upvote 0
One way would be to extract the year part in another column with a formula, and use this new column as your Primary sort field, and then your values above as your Secondary sort field.
As long as the added column does not affect the other formulas I have in the workbook. Do you have a formula in mind that I could try?
 
Upvote 0
The earliest year in the database is 2013
In that case I think you will need something like Joe suggested otherwise 2013 and 2023 are likely to get sorted together if you are just using the first digit.

Here is a possibility. Use this formula then sort both columns together using column B as the sorting column.

20 09 10.xlsm
AB
1
279382117
380306118
491547119
501974220
611520221
721330222
836533223
936533113
Sort Years
Cell Formulas
RangeFormula
B2:B9B2=(RIGHT(A2,1)&LEFT(A2,1))+0
 
Upvote 0
.., or if the data does contain the parentheses as well

20 09 10.xlsm
AB
1
2793821 (2017 YOM)2017
3803061 (2018 YOM)2018
4915471 (2019 YOM)2019
5019742 (2020 YOM)2020
6115202 (2021 YOM)2021
7213302 (2022 YOM)2022
8365332 (2023 YOM)2023
9365331 (2013 YOM)2013
Sort Years
Cell Formulas
RangeFormula
B2:B9B2=MID(A2,9,4)+0
 
Upvote 0
I added the formula to cell G2 but changed it to =(RIGHT(F2,1)&LEFT(F2,1))+0 and it did not work. Sorry, newbie at Excel here.
Am I missing something? Do the cells in column G needs to be a specific format? They are 'General' as default.

1599753138238.png
 
Upvote 0
Also, note the cells I highlighted in RED. Can you also advise how to format the cells that when a serial number is repeated in that column, it highlights those cells RED automatically?
 
Upvote 0

Forum statistics

Threads
1,215,350
Messages
6,124,439
Members
449,160
Latest member
nikijon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top