Sort range - mix of text and numbers

Formula11

Active Member
Joined
Mar 1, 2005
Messages
440
Office Version
  1. 365
Platform
  1. Windows
I'm sorting a large range of data, based on values in column A.
Column A values are a mix of text and digits, so a String.
Example below shows sorting for an example case. There's an issue when there's a different count of digits.
Is there a fix for this, like a setting in Excel.

1686010859348.png
 
This formula approach may not suit your large data, but let's pursue it for now.
Otherwise, before considering a macro you could still consider using a helper column & using that column as your sort column.

23 06 06.xlsm
ABCD
1NameDescriptionOtherHelper
2text-2107This is text-2107Comment 1text-000002107
3text-21074This is text-21074Comment 3text-000021074
4text-2109This is text-2109Comment 2text-000002109
5next-31074This is next-31074Comment 12next-000031074
6next-3109This is next-3109Comment 11next-000003109
Sort (2)
Cell Formulas
RangeFormula
D2:D6D2=LEFT(A2,FIND("-",A2))&TEXT(-MID(A2,FIND("-",A2),99),REPT(0,9))


After sorting on column D:

23 06 06.xlsm
ABCD
1NameDescriptionOtherHelper
2next-3109This is next-3109Comment 11next-000003109
3next-31074This is next-31074Comment 12next-000031074
4text-2107This is text-2107Comment 1text-000002107
5text-2109This is text-2109Comment 2text-000002109
6text-21074This is text-21074Comment 3text-000021074
Sort (2)
Cell Formulas
RangeFormula
D2:D6D2=LEFT(A2,FIND("-",A2))&TEXT(-MID(A2,FIND("-",A2),99),REPT(0,9))
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Thanks Peter, can confirm the speed is quick for large data (tens of thousands of rows, and 20 columns).
Some checks ... there were issues, as an example, such as sorted by character, then digit, then character again.
Will have to follow up but can't now.

Otherwise it may have to be arrays using VBA.
 
Last edited:
Upvote 0
Yes with the SORTBY solution.
But I spoke too soon as saw an issue with sorting ... for example see below.

1686019022995.png
 
Upvote 0
Well, we didn't have any sample data like that before!! :eek:

Previously we simply had a text value followed by a dash followed by a number & my interpretation was to sort by the text first and then by the number.
Perhaps you could explain what the logic is of your required sort, particularly with data like D-001-t which does not end with a number and 240-02-004 which does not start with text? :confused:

BTW, it would make it much easier to help if you provided sample data & expected results with XL2BB so we didn't have to manually type data to test with.
 
Upvote 0
Sorry Peter I agree, as it seems that sorting is quite nuanced.

The goal was for the Excel list to match whatever sorting occurred in Windows Explorer (Windows 10, if relevant).
Sorting in Explorer is different to Excel.
As a guess this will have to be done in VBA.
Will have to do more research before continuing I think.

Sorry if it was a bit of a time waster.
 
Upvote 0
I don't think that there was ever any doubt about that was there?
What are you getting at with that comment?

Just saying since the entire column is 'text' & no pattern to work from, It is going to be nearly impossible to solve this with a formula or VBA code, that I can think of anyway.
 
Upvote 0

Forum statistics

Threads
1,215,793
Messages
6,126,936
Members
449,349
Latest member
Omer Lutfu Neziroglu

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