Forum Discussion

Marco365's avatar
Marco365
Brass Contributor
Jan 21, 2021
Solved

Sort Numbers Within A Cell In Excel?

Hi everyone, 

 

I am just looking for a formula to sort numbers within a cell

 

042 = 024 or 420

 

3406 = 0346 or 6430 

 

32 = 23 or 32

 

 

 

 

  • Marco365 Thanks for the file and clarification. Rather than creating a lot of manual steps, I thought it was best to create two pivot tables ("pt"). on the basis of the data sheet "1 Sort by cell....."

     

    The first pt counts the number of numbers in each month of the year.

    A second pt creates a list of all dates in the data, with a filter on the number with digits in descending order. I called it "DescNr". This is the basis for individual pt's for each of these numbers. They look like this:

    Don't worry! You don't have to create every pt for each "DescNr". Under options on the Pivot Table Analysis ribbon, you can select "Show Report Filter Pages...". This will create one pt for each of the items in the filter field.

    Perhaps you find this approach acceptable. Almost fully automated and not much room for error.

21 Replies

    • Marco365's avatar
      Marco365
      Brass Contributor

      Riny_van_Eekelen 

       

      Hi Riny,

       

      I am not able to do it so far, I am not sure why. 

       

      I have added more to what I am trying to get done in this file. Let me know if you can see it and if you can help, otherwise I would post the file to get some help.   Thank you so much 

      • Riny_van_Eekelen's avatar
        Riny_van_Eekelen
        Platinum Contributor

        Marco365 Sorry, but you need to be more specific. What I do get is that, for instance the number in E1 = 351. The largest number that can be created from these digits is 531. Similar for E2 and E3. The digits in the respective numbers can all be "re-grouped" to (the largest number) 531. Now, E4 (on 18 sep 2020) has the number 131. How does this one relate to the 531 in J17, also 18 sep 2020? Similar for the next one (331 on 16 sep). And why is there a number "532" in the list of 531's, dated 17 sep 2020? (See picture). Perhaps you accidentally typed it wrong and it should also be 531 and on 14 sep 2020. But why?

           

        Why not create an example of, say, the first 10 numbers on your list and manually produce the full output of what you need, noting down exactly, the logic for each step.

         

         

  • JMB17's avatar
    JMB17
    Bronze Contributor

    Perhaps try:
    =textjoin("",true,SMALL(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),ROW(INDIRECT("1:"&LEN(A1)))))

    You may need to hit Ctrl+Shift+Enter for it work after keying it into the formula bar. For descending order, try replacing "small" with "large".

     

    If you have office 365 and the newer functions (such as sort and sequence), then it could probably be made more efficient. This is a guess as to how you could try the sort function as I don't have that one, but someone else may be able to speak to whether or not it would work:

     

    =textjoin("",true,sort(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))

    • Marco365's avatar
      Marco365
      Brass Contributor

      JMB17 

       

      Hi again JMB17,

       

      How can I tweak this formula to do the same thing for alphabets rather then numbers, for instance, ACBM can become ABCM or MCBA?

Resources