Forum Discussion
Excel not sorting numbers correctly - smallest to largest etc.
These replies are not helping me troubleshoot my issue -
I have no hidden columns, no formulas, nothing but raw data in my spreadsheet - yet when I sort from small to large or vice versa with cell formatting in "number" format, it sorts the majority correctly then puts several at the bottom that are out of sequence. I've copied the cell format of one that sorts correctly and pasted to those that didn't, then resorted to see if it worked but it doesn't. I don't know what to do to fix this major annoying problem - any suggestions are appreciated.
KerrilynnAZ , if in any empty cell you try =ISNUMBER() on one the cells which are in the bottom, what will be the result?
- KerrilynnAZJun 07, 2019Copper Contributor
SergeiBaklan I ended up googling the formula =CLEAN(A2) to strip nonprintable characters from cell text and was able to get that to work in this situation. Rather cumbersome but at least I had success and will be able to continue using that to help me. I'm going include my notes that I wrote that worked for me in case anyone else can find this of benefit to them:
Issue: Exporting to Excel from another database may have created characters that are hidden which impacts the ability to sort columns correctly. (Simply changing the cell format from text or general or to number format will not correct the problem) This can be fixed using the CLEAN formula below:
=CLEAN(A2) Strip non-printable characters from the cell. Non-printable characters constitute the first 32 characters of the 7-bit ASCI code, which houses the 128 text characters used by all computers for data storage and computing. Because 7-bit ASCI code is widely used in computer processing, copying and pasting data from other applications or business databases frequently copies the nonprintable characters too. To remove nonprintable characters:
As an example:
To clean A2 through A25: (assuming row 1 is the title field)
- Open your spreadsheet and right-click the column letter located to the right of the data column you want to change.
- select "Insert" to create a new "B" column
- Click cell B2 (assuming B1 is the title fields)
- Press "Shift" key and click cell B25
- Type =CLEAN(A2) then press "Ctrl-Enter"
- To now clean up the spreadsheet and remove the created column:
- Select & Copy the data from the newly created column (B)
- Paste Special the “Value” into the cleaned column (A)
- Delete the newly created column (B)
- Click the info icon if there is a green box in the left of the cell and choose “convert to a number” for those that have it. If none, do nothing.
- Re-sort the column and verify that the sort worked correctly.
This HELPED me resolve my issue - I hope it helps another too!
- RhodessaSep 01, 2022Copper Contributor
OMG! Thank you so much for the detailed instructions! It took several tries because I was using different columns and had to change the directions to fit my labels, but it worked! Then I fixed all the green boxes and moved the decimal (which added zeros where necessary). I now have a column of numbers with two decimal places and they sort perfectly. Thank you, thank you, thank you from the bottom of my heart.
- DLansJun 13, 2019Copper Contributor
KerrilynnAZ Thats how I ended up solving the problem for me :) Copying data indeed somehow created characters that I couldn't see, but with the =CLEAN function and the steps you described I could sort them correctly.
- KerrilynnAZJun 13, 2019Copper Contributor
DLans YOU just made my day! ;-) It makes it worthwhile when you can share knowledge that someone else finds of benefit - especially in these scenario's. I hate wasting time trying to figure out problems that I can't find quick answers to in order to keep me moving forward, LOL. Thank You!
- Open your spreadsheet and right-click the column letter located to the right of the data column you want to change.