Closed Thread
Results 1 to 13 of 13

How to sort in within a cell alphabetically For Excel

  1. #1
    Registered User
    Join Date
    06-23-2021
    Location
    US
    MS-Off Ver
    365
    Posts
    16

    How to sort in within a cell alphabetically For Excel

    I have a list of names in one cell and I am trying to sort them alphabetically. I am having trouble finding some way to make this happened. I made unaware of any Macro code that would be able to sort the string text in one cell alphabetically. I have a list of names that go over ten columns and more than one name in each cell. Understand I am not trying to sort a column, I am trying to sort text within one cell, not a column. Please help if you can. Thank you in advance.

    Attached is an example of an excel sheet, so you are able to see what I am trying to do.
    Attached Files Attached Files
    Last edited by Jumper23; 06-24-2021 at 02:45 PM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: How to sort in within a cell alphabetically For Excel

    lot easier to give advice if we see the workbook.
    see big yellow banner - how to upload your workbook.
    torachan.

  3. #3
    Registered User
    Join Date
    07-07-2019
    Location
    Bangladesh
    MS-Off Ver
    2019
    Posts
    11

    Re: How to sort in within a cell alphabetically For Excel

    The fastest way to sort alphabetically in Excel is this:

    1) Select any cell in the column you want to sort.
    2)On the Data tab, in the Sort and Filter group, click either A-Z to sort ascending or Z-A to sort descending. Done!
    Attachment 737684

    The same buttons can also be accessed from Home tab > Editing group > Sort and Filter:
    Attachment 737685

    **Note: In some situations, mostly when just one or a few cells in the middle of your data set are selected, Excel is unsure which part of the data to sort and asks for your instructions. If you'd like to sort the entire table, leave the default Expand the selection option checked, and click Sort:

    If you need any further explanation, you are requested to upload your excel file.

    Best regards,
    Ibrahim.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,064

    Re: How to sort in within a cell alphabetically For Excel

    The big question is... how are the multiple values in a single cell separated?? Here, I have assumed that they have been separated by a "carriage return", i.e. CHAR(10). So, to sort text values in a single cell, ensure text wrapping is on and use:


    =TEXTJOIN(CHAR(10),TRUE,SORT(FILTERXML("<A><B>"&SUBSTITUTE(A1,CHAR(10),"</B><B>")&"</B></A>","//B")))
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: Lá fhéile Pádraig sona dhaoibh

  5. #5
    Registered User
    Join Date
    06-23-2021
    Location
    US
    MS-Off Ver
    365
    Posts
    16

    Re: How to sort in within a cell alphabetically For Excel

    Hello Glenn,

    I tried the text join and for some reason, it did not work. The text joins worked on your cell but when I tried it on mine it did not sort the names at all.

    If you could help with this it would be so great.

    Thanks
    Jumper23
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-23-2021
    Location
    US
    MS-Off Ver
    365
    Posts
    16

    Re: How to sort in within a cell alphabetically For Excel

    Hello torachan ,

    This is an example of the workbook that I am working on.
    Please let me know if you could help with this.
    Jumper23
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    06-23-2021
    Location
    US
    MS-Off Ver
    365
    Posts
    16

    Re: How to sort in within a cell alphabetically For Excel

    Hello mkhalil,

    I have attached an excel file so you can see what I am working with. I am trying to sort the string text within one cell in alphabetical order.
    This has been a difficult challenge for me.

    Jumper23
    Attached Files Attached Files

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,064

    Re: How to sort in within a cell alphabetically For Excel

    That is because you didn't tell us how the names were separated. I TOLD you that I had assumed they were carriage return separated. It turns out that they're space separated, so:

    =TEXTJOIN(" ",TRUE,SORT(FILTERXML("<A><B>"&SUBSTITUTE(A1," ","</B><B>")&"</B></A>","//B")))
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-23-2021
    Location
    US
    MS-Off Ver
    365
    Posts
    16

    Re: How to sort in within a cell alphabetically For Excel

    Hello Glenn,

    Can you explain how this formula works?
    Last edited by AliGW; 06-25-2021 at 01:01 AM. Reason: PLEASE don't quote unnecessarily!

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,064

    Re: How to sort in within a cell alphabetically For Excel

    =TEXTJOIN(" ",TRUE,SORT(FILTERXML("<A><B>"&SUBSTITUTE(A1," ","</B><B>")&"</B></A>","//B")))

    The formula relies on FILTERXML, very useful for all sorts of parsing and which has the following syntax:

    =FILTERXML(XML_string,XPATH)

    So the first part is to convert your cell to a valid XML string. If you think of your string like a family tree… the whole string is a parent, and the individual names are children. So to get a valid XML string you need one identifier (Node) for the entire string (I used the letter A) and one to designate each child separately (I used the letter B).

    Within the string, the names are space separated, to I replaced them with a B-B node separator:
    SUBSTITUTE(A1," ","</B><B>")

    To complete a valid XML string, I added "<A><B>" at the start and </B></A>" at the end. The XML string is then fed into FILTERXML where the XPATH bit… "//B" isolates all the B nodes (ie the names) in a semicolon-separated array.

    SORT then sorts them into alphabetical order and TEXTJOIN joins them back together into a single string, again separated by a space.

    Clear enough??

  11. #11
    Registered User
    Join Date
    06-23-2021
    Location
    US
    MS-Off Ver
    365
    Posts
    16

    Re: How to sort in within a cell alphabetically For Excel

    Hello Glenn,

    Thank you so much for this. It has been a huge help you have no idea.

    Jumper23
    Last edited by AliGW; 12-18-2023 at 03:29 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  12. #12
    Registered User
    Join Date
    12-13-2023
    Location
    Melbourne
    MS-Off Ver
    Office 365
    Posts
    5

    Re: How to sort in within a cell alphabetically For Excel

    Would anyone know a way to achieve this on Excel for web.

    FILTERXML is not supported on Excel for web.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,981

    Re: How to sort in within a cell alphabetically For Excel

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar or even the same to this thread, we have a rule that you open your own thread on the issue and do not piggy back another member's thread.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can you sort data alphabetically in one particular cell?
    By hawkeye12345 in forum Excel General
    Replies: 23
    Last Post: 10-02-2021, 11:43 PM
  2. Sort alphabetically within a cell
    By DianaM in forum Excel General
    Replies: 2
    Last Post: 08-04-2017, 02:08 PM
  3. [SOLVED] can i sort data alphabetically in one particular cell?
    By uuthbey in forum Excel General
    Replies: 6
    Last Post: 01-31-2014, 02:28 PM
  4. [SOLVED] Excel sort alphabetically doesn't move cell border
    By Marco-Kun in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-25-2013, 11:13 AM
  5. Excel sort alphabetically doesn't move cell border
    By Marco-Kun in forum Excel General
    Replies: 0
    Last Post: 04-18-2013, 08:21 AM
  6. Can you sort data alphabetically in one particular cell?
    By MJExcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2012, 08:57 AM
  7. [SOLVED] How do I sort in Excel alphabetically?
    By Jennifer in forum Excel General
    Replies: 2
    Last Post: 01-20-2006, 12:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1