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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
like a setting in Excel.
No, but you have a couple of options.

If you really want the actual data sorted, then you could create a helper column as shown in col B below and sort both columns using col B as the sort column.

Otherwise, with no helper column as such you could leave the original data as is and use a formula like D2 (if the leading text in col A is always the same length) or F2 (if the leading text can vary in length)

23 06 06.xlsm
ABCDEF
1Name
2text-21072107text-2107text-2107
3text-2107421074text-2109text-2109
4text-21092109text-21074text-21074
Sort
Cell Formulas
RangeFormula
D2:D4D2=SORTBY(A2:A4,MID(A2:A4,6,99)+0)
F2:F4F2=SORTBY(A2:A4,-MID(A2:A4,FIND("-",A2:A4),99))
B2:B4B2=-MID(A2,FIND("-",A2),99)
Dynamic array formulas.
 
Upvote 0
Are you trying to sort the column using vba code or what? Please be specific in what you are asking for.
 
Upvote 0
Peter, thanks for the suggestions above.

I should have been more specific as you mention johnnyL.
- The data is large, in the tens of thousands of rows.
- There are multiple columns which have to be sorted as well.
- The prefix "text" as shown in the example above, is a variable and can be something else.
I didn't mention VBA because I thought it may take a long time, but if it can be done this way, no objection.

1686013668593.png
 
Upvote 0
Yes I did, this is what eventuates.
It may be that I should follow this through and get other columns to match somehow.

1686015003231.png
 
Upvote 0
What am I missing? It appears that your column F is the sort result of column A
 
Upvote 0
Yes but if you look at "next-#" this should be before "text-#".
But it may be enough to get me started at least. I haven't looked at it further yet.
 
Upvote 0
ahhh, I see now, thanks for pointing out that you changed the original data, I see the problem now.
 
Upvote 0
This formula approach may not suit your large data, but let's pursue it for now.

23 06 06.xlsm
ABCDEFG
1NameDescriptionOtherNameDescriptionOther
2text-2107This is text-2107Comment 1next-3109This is next-3109Comment 11
3text-21074This is text-21074Comment 3next-31074This is next-31074Comment 12
4text-2109This is text-2109Comment 2text-2107This is text-2107Comment 1
5next-31074This is next-31074Comment 12text-2109This is text-2109Comment 2
6next-3109This is next-3109Comment 11text-21074This is text-21074Comment 3
Sort (2)
Cell Formulas
RangeFormula
E2:G6E2=SORTBY(A2:C6,LEFT(A2:A6,FIND("-",A2:A6))&TEXT(-MID(A2:A6,FIND("-",A2:A6),99),REPT(0,9)))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,215,113
Messages
6,123,165
Members
449,099
Latest member
bes000

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