sort text numbers as number

J

JACOB

I have a list like this
1-apple
2-orange
....
11-pears
12-grapes..
Now when I sort it, it will sort number 2 after number 12 because it takes
it as text, how can I have Excel sort it by the numeric value of the
begining of the filed?
 
E

EarlK

Jacob,

You can make a helper column, and sort on that column.

=LEFT(A2,SEARCH("-",A2)-1)

This should yield the number part at the beginning of the cell - it looks
for a hyphen. It will fail if it doesn't find a hyphen; the formula can be
expanded to behave more nicely if that's a possibility.

You can hide the helper column, but it may not be possible to use the sort
buttons on the toolbar (they're a bit dangerous anyway). Works fine with
Data - Sort.

Regards from Virginia Beach,

EarlK
 
R

Rob

I would suggest storing different data types in different
fields so you don't have this problem - use the
spreadsheet as it is designed to be used in other words.
You'd have a column labled 'Number' with the number of
thisngs, and another column next to it labeled "Fruit'
which specifies what kind of fruit. Now you can sort buy
numbers or by which kind of fruit. To convert your
existing data you could select the column in question and
split it into numeric and text columns using the
Data...Text to Columns feature. Make a backup copy of
your spreadsheet and give it a try. This will of course
change the number of rows in your data sheet which might
cause problems depending on what functions are coded to do
whatever else to with the data. Let me know if you need
more help....
 
S

Steve Farrar

JACOB said:
I have a list like this
1-apple
2-orange
...
11-pears
12-grapes..
Now when I sort it, it will sort number 2 after number 12 because it takes
it as text, how can I have Excel sort it by the numeric value of the
begining of the filed?

If your first item is Cell A1,put this formula in B1, then copy down
to the last row in Column A
=VALUE(LEFT(A1,FIND("-",A1)-1))
Then you can sort by Column B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top