Forum Discussion

Ravie72's avatar
Ravie72
Copper Contributor
Mar 04, 2021

How to sort numbers with a space in the one cell

Hi - Have been searching online but can't find the correct formula. Is there a way to sort numbers in order i.e. lowest to highest within one excel cell as per below when there is a space between values? So in the cell below can you order the data as 1 4 6 24 35 45 52? Thanks for your help.

35 24 45 4 42 6 52 1

21 Replies

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor
    With permission from everyone, even if I still think that a file (without the syllable data) can present a clear picture for everyone, I now add a quick and easy solution.

    Mark data (incl. Blank lines) - auto filter - do not show empty
    then sort the same marking and then auto-filter off.
    Without formula 🙂

    Is just a thought, if it suits you I'll be happy. If it doesn't fit, just ignore it.

    Nikolino
      • NikolinoDE's avatar
        NikolinoDE
        Gold Contributor
        To err is human, probably correct text in the wrong post.
        That's what happens when you want to multitask everything.
        Thanks for the hint
  • Ravie72 

    Just to show how different a modern version of Excel can be, the following worksheet formula provides a very different solution strategy 

    It is a mix of insider beta functionality and a legacy XLM macro 4 function.

     

     

    • Rajesh_Sinha's avatar
      Rajesh_Sinha
      Iron Contributor
      Please elaborate your post & share that using which editor you have created this Macro supported by the new launch LAMBDA,, and the version which supports all these CELL.SORT ,, EVAL,,,, since this forum has users still working with older versions and not comfortable with VBA macros even!!
      • PeterBartholomew1's avatar
        PeterBartholomew1
        Silver Contributor

        Rajesh_Sinha 

        Since September 2018 there has been seismic changes in Excel.  By 'seismic', I mean it is now possible to write Excel solutions that an average user might not even recognise as being Excel.  In the post,  have only used worksheet functions, there is no macro other than the old EVALUATE function that takes a text string and evaluates it as if it were a formula.

         

        The Excel 365 changes (later in the year this should also be Office 2021) I refer to are to make array formulas the default without needing CSE.  The there is the LET function that allows every alternate parameter to be a name created by the user, which refers to the formula in the following parameter.  This helps make sense of deeply nested formulas and those that repeat the use of a calculation fragment.

         

        The final change, that is currently only on release in the beta versions of Excel, is the LAMBDA function.  It was this that allowed me to define the name

        = CELL.SORT(seq)

        which refers to the formula written over several lines (using Alt/Enter to generate a line feed).  The LAMBDA function has the names to be used within the formula as its initial parameters and the function to evaluate as its final parameter.  The thing that makes the function so revolutionary is that the LAMBDA is followed by the actual parameters to be used in the formula, held within parentheses.  These are then substituted one for one in place of the dummy parameters which means that the same defined function can be used to refer to many different areas of the worksheet. 

         

        What makes the whole thing so startling to anyone schooled to accept traditional spreadsheet practice is that the resulting formulae read more like a snippet of code than a conventional formula.

         

  • Rajesh_Sinha's avatar
    Rajesh_Sinha
    Iron Contributor

    Ravie72 

     

    You may try this, works with all version of Excel:

    • An array (CSE) formula in cell C50:

     

     

    {=IFERROR(SMALL(IF((COUNTIF($C$49:C49, $A$50:$A$61)=0)*ISNUMBER($A$50:$A$61), $A$50:$A$61, "A"), 1), INDEX($A$50:$A$61, MATCH(SMALL(IF(ISTEXT($A$50:$A$61)*(COUNTIF(C$49:$C49, $A$50:$A$61)=0), COUNTIF($A$50:$A$61, "<"&$A$50:$A$61), ""), 1), IF(ISTEXT($A$50:$A$61), COUNTIF($A$50:$A$61, "<"&$A$50:$A$61), ""), 0)))}

     

     

    • Finish formula with Ctrl+Shift+Enter , and fill down till needed.

    If you are using higher version then yo may try this

     

     

    =SORT(UNIQUE(FILTER(A50:A61,A50:A61<>"")))

     

     

    Another is:

    • Apply  Auto Filter to exclude blank cells, which actually does get rid of Null Strings. Then SORT the data.

     

    • Adjust cell references in the formula as needed.
  • JMB17's avatar
    JMB17
    Bronze Contributor
    If you have the textjoin, filterxml, and sort functions, then I believe this will work:

    =TEXTJOIN(" ",TRUE,SORT(FILTERXML("<L><I>"&SUBSTITUTE(A1," ","</I><I>")&"</I></L>","//I")))

    If you don't have sort, then I believe this will also work (may need to hit Ctrl+Shift+Enter after keying it into the formula bar if you don't have the latest excel version):

    =TEXTJOIN(" ",TRUE,SMALL(FILTERXML("<L><I>"&SUBSTITUTE(A1," ","</I><I>")&"</I></L>","//I"),ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1))))

    • Ravie72's avatar
      Ravie72
      Copper Contributor

      JMB17 Hi - Thanks for trying. I have the cell in A1. But neither formula worked and comes up with a value error. 

      • JMB17's avatar
        JMB17
        Bronze Contributor

        Ravie72 

         

        Though I really think it would work, I don't have the sort function so can't confirm it. But, I can confirm the second one should work, provided you have those functions:

         

         

         

         

Resources