Forum Discussion
Sort Numbers Within A Cell In Excel?
- Jan 24, 2021
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.
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)))
- Marco365Jan 26, 2021Brass Contributor
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?
- SergeiBaklanJan 26, 2021Diamond Contributor
Marco365 , it shall work with texts
- Marco365Jan 27, 2021Brass ContributorThank you Sergei!
- JMB17Jan 26, 2021Bronze Contributor
Try:
=TEXTJOIN("",TRUE,CHAR(SMALL(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),ROW(INDIRECT("1:"&LEN(A1))))))
And, you should be able to replace "small" with "large" to go in descending order. Also, I'm assuming the data does not mix upper/lower case?
- Marco365Jan 27, 2021Brass ContributorThank you JMB17!