Forum Discussion

Jamie Collins's avatar
Jamie Collins
Copper Contributor
Jun 23, 2018

Excel not sorting numbers correctly - smallest to largest etc.

I have been helping a friend organize a excel file with 4 digit numbers.  These numbers are in the 6000 to 8000 range.  When I filter or sort the numbers from smallest to largest there are numbers , in the 6200 to 6800 range, missing where they should be and then excel places them in order farther down in the 7000 to 8000 range.  I am sure there is an answer and I did find that version 16.9 and above have issues.  Is anyone else having this issue and if so, what can be done?

  • WillT99's avatar
    WillT99
    Copper Contributor

    @@

    I had the same problem but my numbers were not from internet, they were from another page in the same worksheet.

    Turns out that the problem was fixed when I transfered my formula to the same page as the numbers it referenced. 

    The part with : 'pagexx'! Seemed to be the problem.. 

    Hope this helps someone

  • NACAlyssa's avatar
    NACAlyssa
    Copper Contributor

    Not sure if anyone else has come into issues, I was attempting to use the =CLEAN formula to fix my own spreadsheet, but it was acting wonky when I tried to insert a row. I realized that my table did not extend further. 

     

    So if anyone else is working in a table they've set up in excel, you may have to check on the size of your table. a column wasn't ordering properly because a set of the cells were not in the table. I resized the table down further and it fixed the issue immediately 🙂

    • William_Bila's avatar
      William_Bila
      Copper Contributor

      NACAlyssa 

       

      I didn't import data. It says 55 is bigger than 60 and 37 is bigger than 40.  I calculated sums across columns.  I decided to copy and paste values, so there wouldn't be any calculations. Stilll in the same order.  What is the point of having excel if it can't do basic math? I don,t understand why I have to make it more complicated and look up the =clean function for a list of 80 names and numbers to be sorted correctly. 

      • mathetes's avatar
        mathetes
        Silver Contributor

        William_Bila 

        What is the point of having excel if it can't do basic math?

         

        Excel can and does do basic math.  It's not perfect, and every once in a while somebody comes up with an actual bug or quirk, but it's not in the realm of basic math. Given the millions using Excel over the years, around the world, the odds that you have discovered a fatal flaw in Excel's abilities with basic math are less than infinitesimal.

         

        And you are coming into a thread that began over  two years ago and may or may not be applicable to your situation.

         

        So why don't we back up a bit and get a more complete description from you of what you're working with and what is and is not working. And, if it's possible, without violating confidentiality or proprietary data restrictions, it would help us help you if you could post a copy of your actual workbook on OneDrive or GoogleDrive, with a link pasted here that grants edit access.

  • nullnull's avatar
    nullnull
    Copper Contributor

    I made an account just to let anybody Googling this know...

     

    My numbers had spaces after them, darn things! =ISNUMBER could tell they weren't "numbers" even though I'd set the cell format to Number. =CLEAN didn't work; paste special > values didn't work.

     

    What worked was.... =TRIM! (I only thought of this because I just used Data > Trim Whitespace in Google Sheets last week.)

     

    So if you paste special (as values) your data from the web, and/or clean them, and they still won't sort, try:

     

    =TRIM(A1)

    • nullnull 

      Just in case, CLEAN() removes characters with ASCII codes from 0 to 31, TRIM() removes space (code 32). But no one of them removes non-breaking space (code 160) which is the most often case when copy/paste from web. 

      • JRVM1's avatar
        JRVM1
        Copper Contributor

        SergeiBaklan 

        Any other ideas? Neither =clean(A2) nor =trim(A2) work in my case.

        My data is not from the web, is a result of a INDEX MATCH horizontal lookup. 

  • KerrilynnAZ's avatar
    KerrilynnAZ
    Copper Contributor

    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's avatar
        KerrilynnAZ
        Copper 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)

        1. Open your spreadsheet and right-click the column letter located to the right of the data column you want to change.
          1. select "Insert" to create a new "B" column
          2. Click cell B2 (assuming B1 is the title fields)
          3. Press "Shift" key and click cell B25
          4. Type =CLEAN(A2) then press "Ctrl-Enter"
        2. To now clean up the spreadsheet and remove the created column:
          1. Select & Copy the data from the newly created column (B)
          2. Paste Special the “Value” into the cleaned column (A)
          3. Delete the newly created column (B)
          4. 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.
          5. Re-sort the column and verify that the sort worked correctly.

            This HELPED me resolve my issue - I hope it helps another too!
  • Nope, in my case it works as expected. Are your numbers are integers in Excel, or that texts? Did you generate them manually (e.g. fill series) or copy/pasted from Web for example?

    • Jamie Collins's avatar
      Jamie Collins
      Copper Contributor
      They are copy and pasted all from the same site. Chunks of the numbers will sort correctly but then further down they stop sorting right.
      • SergeiBaklan's avatar
        SergeiBaklan
        MVP

        If they are not generated within Excel but copy/pasted from the Web, most probably you have non-printable characters inside your cells with numbers. That doesn't matter you used same site or not.

        You may check by LEN() applied to cells if all of them returns 4.

         

        If not you may apply =CLEAN(A1)*1 to such cells to remove non-printable characters.

Resources