Why does Data/Sort not work in this example? Perhaps too many lines of data?

Carl Soholt 0 Reputation points
2026-11-25T20:13:48.7433333+00:00

I imported a report into Excel that included a column that identified items as either nothing on the line (blank) or Invoice or Payment.

I tried sorting the rows of the spreadsheet based on that column. (Data-Sort-by column X)

The sorted result had Invoice and Payment mixed - looks like the (blank) lines were sorted to the bottom at least.

Why does this simple alphabetical sort not work?

The only unique thing about this data is there are about 18,700 lines to sort.

Also, I tried creating a new column that put the value 1 if the source column said "Payment" and zero if not.

Then I tried sorting numerically using this column - same result.

What is wrong?

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

2 answers

Sort by: Newest
  1. Marcin Policht 113.9K Reputation points MVP Volunteer Moderator
    2026-11-25T20:24:09.4566667+00:00

    The number of rows shouldn't be a problem. Excel can easily handle 18,700 rows. Since both alphabetical sorting and your numeric helper-column approach produced the same result, I would first suspect an issue with the structure of the imported data or the way Excel is interpreting the values.

    The first thing to check is whether Excel is sorting the entire dataset as one range. Select the entire dataset, including all columns, then choose Data > Sort. Make sure My data has headers is checked if the first row contains headings. If Excel prompts you to expand the selection, choose Expand the selection. Also check for completely blank rows that might divide the report into separate data regions.

    Another possibility is that the imported values contain invisible characters. For example, some cells might contain Invoice while others contain Invoice (a trailing space) or a nonbreaking space. These values look identical but are technically different. To clean the values, create a helper column using this formula:

    =TRIM(CLEAN(SUBSTITUTE(X2,CHAR(160)," ")))

    Replace X2 with the appropriate cell reference, fill the formula down, and then copy the results and use Paste Special > Values. Try sorting using this cleaned column.

    You can also use the Filter feature (Data > Filter) on the original column. Examine the dropdown list to see whether Excel recognizes exactly three distinct entries: (Blanks), Invoice, and Payment. If additional entries appear that look identical to Invoice or Payment, the imported data contains inconsistent text values.

    Finally, check whether the report contains merged cells or blank rows within the data. These can interfere with sorting and cause Excel to treat portions of the report as separate ranges.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-11-25T20:14:07.03+00:00

    The row count is not the issue in the provided guidance. The more likely causes are data consistency or the selected sort range.

    Most likely reasons for the mixed result:

    1. The values in that column are not truly identical text values.
      • Leading spaces affect sort order.
      • Blank cells sort last, but cells that contain one or more space characters are not considered blank.
      • If some entries contain hidden spaces, Payment and Invoice can appear to sort unexpectedly.
    2. The sort range may not include the full data range.
      • If there is a blank column inside the dataset, Excel may not treat all columns as one continuous range.
      • A Microsoft Q&A example shows that a blank column can prevent the full row range from sorting together unless that blank column has a header.
    3. Hidden rows or columns can affect the result.
      • Hidden rows are not moved when sorting rows, and hidden columns are not moved when sorting columns.
    4. Formula-based helper values may need the sort reapplied.
      • If the helper column uses formulas, recalculation can change returned values, and the sort may need to be applied again.

    What to check:

    1. Select the entire dataset before sorting, not just one cell.
    2. Unhide any hidden rows and columns.
    3. Check the sort column for leading spaces or cells that only look blank but actually contain spaces.
    4. If there is a completely blank column inside the data range, add a header to that column so Excel includes the whole range.
    5. If using the helper column, confirm the helper values are real numbers and then sort the full dataset by that column.
    6. In Home > Sort & Filter > Custom Sort, verify whether My data has headers is set correctly.

    A key detail from the sort rules:

    • Blank cells are always placed last.
    • A truly blank cell is different from a cell containing spaces.

    So if the “blank” entries moved to the bottom but Invoice and Payment still look mixed, the strongest explanation is inconsistent cell contents such as leading/trailing spaces, or a partial sort range rather than too many rows.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.