How do I fix sorting issues when Numbers don't sort correctly?

I have attempted to sort a sheet by column A-Z but it still appears to be sorting by choosing the first two numbers. Is there a process to rectify this please. Example below.

21 M&M LARGE BREEDS 4YRS & OVER

5 COBS

7 M&M LARGE BREEDS

20 COBS

2 VETERANS


Sort results

2 VETERANS

20 COBS

21 M&M LARGE BREEDS 4YRS & OVER

5 COBS

7 M&M LARGE BREEDS



[Re-Titled by Moderator]

Original Title: Sort sheet numbers with text

Posted on Jun 3, 2025 1:20 AM

Reply
13 replies

Jun 3, 2025 7:09 AM in response to Puzzle999

If you want to sort the numbers as numbers and not text values then you can try something like this:




Add a new column, in the example column B.


In B2 of the example filled down:


=TEXTBEFORE(A2," ")*1


This grabs the leading "number" and coerces from text to a number by multiplying it by 1.


Then sort on column B.


Note: if your region uses , as the decimal separate then use ; instead of , in the formula, e.g.,


=TEXTBEFORE(A2;" ")*1


More on the function here:


TEXTBEFORE - Apple Support


SG


Jun 3, 2025 3:19 AM in response to Puzzle999

To your column A, add a column B


In B2 use this formula TEXTSPLIT(A2;” “)


It will ask you to add more columns in relation to the length of the A2 string


Drag B2 down and you will get like in TABLE 1



Now order column C to get as in column A of TABLE 2



You can choose to hide the columns you don't need as in TABLE 3



Another possibility is that you add a column to TABLE 3 com in TABLE 4 and use this formula in A2



SORTBY(B;D;1)


In this way if you add data to column B you automatically sort column A and always keep hidden columns from C onwards


If you don't want to see the 0 in the empty lines of column A choose conditional highlighting


Equal to number 0


Custom style


And choose white as the font color

Jun 3, 2025 3:25 AM in response to Puzzle999

Hi Puzzle999,


If your table looks something like this:

then Column A is formatted as Text (left aligned by default) and sorting by Column A will sort the table alphabetically, not numerically.

Here we go, after sorting Table 1 by column A:


Select Column A and Format Panel (on the right of your document window) and Cell tab > Data Format > Automatic (or Number). That will convert Column A to numbers (right aligned by default).


Now sort:

Please call back with questions.


Regards,

Ian.


Jun 3, 2025 8:03 PM in response to Puzzle999

It is sorting the column correctly. Digits sort before alpha characters.; 0-9 come before "A" and they sort "alphanumerically" as characters, not as numbers (100 is not one hundred, it is the characters "1" "0" "0").


It sounds like you want to ignore the leading numbers and sort by the characters after the numbers. Note that rows like "5 COBS" and "20 COBS" will be ranked the same if you remove the digits, both being "COBS", so whichever comes first in the column will sort higher/first.


I will assume all of your strings have a leading number and a space character.


If your strings are in column A (starting in A2), you can remove the leading digits and the space character with the following formula in cell B2:

=TEXTAFTER(A2," ")

fill down to complete the column

Then sort by column B


If the number matters and you want to ensuire rows like "5 COBS" and "20 COBS" sort numerically, you'll need a column C

C2 = TEXTBEFORE(A2," ")*1

Fill down

Use the Organize sidebar to create a sort that uses both column B and C



I'm not suggesting you do what I say next because the formulas are more complicated but it is another possibility.

If you are using Numbers version 14.4 , an alternate idea is do the sort in another column using formulas without actually sorting the table.



In column B, use the following formula:

=SORTBY(A,REGEX.EXTRACT(A,"(?<=\d ).+"))

or, to also sort numerically so "COB 5" is sure to come before "COB 20",

=SORTBY(A,REGEX.EXTRACT(A,"(?<=\d ).+"),1,1×REGEX.EXTRACT(A,"\d+"))

No manual sorting is required. The formula does it all.





Jun 4, 2025 1:31 AM in response to Puzzle999

Puzzle999 wrote:

The version I'm using is 12.7


So much easier using reasonably up-to-date versions of Numbers, but here is one way you can accomplish the sort with an old version.


Set up a sort column with this formula:


=RIGHT(A2,LEN(A2)−FIND(" ",A2))


Then click the column letter of the new sort column and choose Sort Ascending.


Result:




SG

Jun 3, 2025 5:56 AM in response to Yellowbox

Thank you Yellowbox. Unfortunately the numbers and text are in the same cell. I use a linked form to produce the information. From what I understand the sheet uses a binary method to list. I think one way around this would be to add a "0" to each class number but that would look odd on an entry form. Perhaps if the sheet would automatically add a zero to the start of each class number/name?

Jun 3, 2025 7:03 PM in response to Camelot

Camelot wrote:

> This grabs the leading "number" and coerces from text to a number by multiplying it by 1.

You can also use the VALUE() function to coerce text to a numeric result:

=VALUE(TEXTBEFORE(A2,"")


Nice.


For those adopting this clearer approach be sure to add the missing ) at the end of the formula, .e.g.,


=VALUE(TEXTBEFORE(A2," "))


SG

How do I fix sorting issues when Numbers don't sort correctly?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.