 # Alphanumeric sorting

I have two columns that are connected and I want to sort by the second column, I want it sorted numerically but it keeps moving the numbers with the -1631 to the bottom of the list how do I fix this?

I have other columns on the same spreadsheet that I sort and I get a sort warning asking to read as numbers and I click this and it sorts fine.

Column A has Dollars

Column B has  49900

49815-1631

49816-1631

I want it to read  49815-1631

49816-1631

49900

50020-1631

and I want to be able to sort this while sorting Column A so it stays together. I have multiple columns on this spreadsheet that have two columns that are attached.

8 Replies

# Re: Alphanumeric sorting

This is a guess.

I don't think Excel can read 49816-1631 as a number. That is to say, it's NOT a number, not until you (or Excel) does the subtraction. In the meantime, it is, by definition, text. Now, maybe it's a zip code (the way it's formatted, that occurs to me as a possibility). Are those other columns you refer to, where you get prompted to sort as numbers, also "numbers" mixed with text in the same field? If they really are just arabic numerals, even if formatted as text, then Excel is smart enough to treat as numbers, but what you have here, with the "-" dividing one set of numerals from another is text and can't be other than that.

As I said, it's a guess, but a semi-informed one. If you'd care to post the spreadsheet, or a portion of it, we can test my hypothesis.

# Re: Alphanumeric sorting

@mathetes Hi. You will have to interpret the part before the minus sign as numeric.

c4 =IFERROR(NUMBERVALUE(LEFT([@Data];FIND("-";[@Data])-1));[@Data])

FIND("-";[@Data])-1)

Find the minus and substract one to find the numnur of digits.

LEFT([@Data];FIND("-";[@Data])-1))

Get that number of characters

NUMBERVALUE(LEFT([@Data];FIND("-";[@Data])-1))

Turn it into a numeric value

IFERROR(NUMBERVALUE(LEFT([@Data];FIND("-";[@Data])-1));[@Data])

If there is no minus FIND will generate an error. If so, return the value as is Column D and E are optional depending on your need.

d4 =IFERROR(NUMBERVALUE(RIGHT([@Data];LEN([@Data])-FIND("-";[@Data])));0)

e4 =[@[Num 1st]]-[@[Num 2nd]]

[@Data] means same row in pyamas tables field Data.
If using an ordinary range, replace [@Data] with B4.

Generally, I prefer using MID since it's one function that can be used also for left and right. In the attached file though, LEFT and RIGHT are used.

# Re: Alphanumeric sorting

Here is picture of my spreadsheet. One column is the dollar amount the other column is an invoice number and I need the invoice number in numerical order so I highlight the 2 columns under the vendor to sort by the invoice number.

Northeastern Refrigeration OP Aquatics The Plumbing Source Rinaldi Landscape

Amount Inv. # Amount Inv. # Amount Inv. # Amount Inv #

\$(1,940.00) 1377712142 \$(631.50) 1197576-000 \$(355.00) 212807 \$(835.00) HANA070121
\$(4,736.00) 1435712742 \$(766.50) 1201297-000 \$(520.00) 212572-1631 \$(828.00) HAR070121-1563
\$(4,002.00) 1446312852 \$(766.50) 4080605-000 \$(1,049.10) 214313-1631 \$(1,900.00) MUS070121
\$(1,136.01) 1473813137 \$(519.00) 1203484-000 \$(310.00) 214401-1631 \$(1,350.00) SEV070121
\$(3,427.60) 1476013162 \$(750.00) 215237 \$(2,060.00) HAR080121-1563

The spreadsheet is set with several vendors all next to each other and I realize it needs to read the numbers as text which is what I am asking how do I get it to read them as text? I used to get a sort warning asking how I want to sort and this would sort them as text but I no longer get this warning.

# Re: Alphanumeric sorting

@mathetesI have attached a sample of my spreadsheet as it is too large to attach more. I am trying to sort the numbers next to the dollar amounts while keeping the dollar amounts next to the numbers so columns E & F need to be sorted together I only want to sort from rows 6 through 16

# Re: Alphanumeric sorting

Thank you for this response but this won't work for what I am trying to do. I already tried it I need the -1631 to stay with the number without losing my sort

# Re: Alphanumeric sorting

@lxj190 Sort by the numeric column but look at the alphanumeric..? ...or turn the column into text format making the numbers treated as strings. # Re: Alphanumeric sorting

Thank you I did try to turn it into text, but it didn't work on all my columns, I found that if I put an ' in front of the number without the dash it gives me the warning box and I can pick sort as text. So thank you for the help

# Re: Alphanumeric sorting

@lxj190 Right- if the invoice number not always begins numeric, then it will not work as proposed.

Good that the apostrophe (comment character) helps. And yet another possibility may be even more helpful;

=IFERROR(TEXT(F6:F18,"0"),F6:F18)

try to turn the data into text, and if it fails, treat it as already text. Assuming Excel 365, there is only one formula, spilling the result. If Excel PDA/pre dynamic arrays, use

=IFERROR(TEXT(F6,"0"),F6)

and fill down.