+ Reply to Thread
Results 1 to 9 of 9

Sort letters before numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    10-28-2008
    Location
    New Jersey
    MS-Off Ver
    2007
    Posts
    15

    Sort letters before numbers

    How can I sort a list of text lexographically (like in a dictionary), with exception that letters (A, B, C, ..., Z) come before numbers (0, 1, ..., 9). So "AAAA" would come before "AAA1A" because "A" comes before "1" in the fourth position.

    For example, sorting the following list:
    AAAB
    99
    AAA1A
    346AA
    ZAAA
    AAAA
    5689
    4AAA

    should give me:
    AAAA
    AAAB
    AAA1A
    ZAAA
    346AA
    4AAA
    5689
    99

    Thanks.
    Last edited by futamura; 08-03-2011 at 01:39 PM. Reason: Clarification

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Sort letters before numbers

    Add an auxiliary column with below formula. Now sort should be auxiliary column then original column.

    =CODE(A2)<58

    Regards

  3. #3
    Registered User
    Join Date
    10-28-2008
    Location
    New Jersey
    MS-Off Ver
    2007
    Posts
    15

    Re: Sort letters before numbers

    Add an auxiliary column with below formula. Now sort should be auxiliary column then original column.

    =CODE(A2)<58
    That doesn't work. That doesn't lexographically order the letters and numbers. I want:
    A < B < C < ... < Z < 0 < 1 < ... < 9.

    So, sorting:
    AAAB
    99
    AAA1A
    346AA
    ZAAA
    AAAA
    5689
    4AAA

    should give me:
    AAAA
    AAAB
    AAA1A
    ZAAA
    346AA
    4AAA
    5689
    99

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Sort letters before numbers

    Maybe this,

    =(CODE(A2)<58)&LEFT(A2)

    Regards

  5. #5
    Registered User
    Join Date
    10-28-2008
    Location
    New Jersey
    MS-Off Ver
    2007
    Posts
    15

    Re: Sort letters before numbers

    Maybe this,

    =(CODE(A2)<58)&LEFT(A2)
    This only looks at the first character. I need a lexographic ordering (like a dictionary), but where letters come before numbers. So, AAAA needs to come before AAAB which needs to come before AAA1.

    It seems like this should be easy to do, through custom lists or something, but I haven't been able to figure it out. Do you (or anyone else) have any ideas?

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Sort letters before numbers

    Ok, this should do the work.

    =(CODE(A2)<58)&A2&REPT(0,50-LEN(A2))

    Regards

  7. #7
    Registered User
    Join Date
    10-28-2008
    Location
    New Jersey
    MS-Off Ver
    2007
    Posts
    15

    Re: Sort letters before numbers

    Ok, this should do the work.

    =(CODE(A2)<58)&A2&REPT(0,50-LEN(A2))
    I appreciate your help, but this does not work either. When you use the above to sort:
    AAAB
    99
    AAA1A
    346AA
    ZAAA
    AAAA
    5689
    4AAA

    you should get:
    AAAA
    AAAB
    AAA1A
    ZAAA
    346AA
    4AAA
    5689
    99

    Is that what you get? (It didn't work for me)

  8. #8
    Valued Forum Contributor
    Join Date
    02-08-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Sort letters before numbers

    This is what I got.

    AAA1A
    AAAA
    AAAB
    ZAAA
    346AA
    4AAA
    5689
    99

  9. #9
    Registered User
    Join Date
    10-28-2008
    Location
    New Jersey
    MS-Off Ver
    2007
    Posts
    15

    Re: Sort letters before numbers

    This is what I got.

    AAA1A
    AAAA
    AAAB
    ZAAA
    346AA
    4AAA
    5689
    99
    This is not what I want. "1" comes after letters, so "AAA1A" must come after "AAAB" (The first 3 positions are the same, but in the fourth position, "1" comes after "B"). Basically, order like a dictionary would if the alphabet were: A, B, C, ..., Z, 0, 1, 2, ..., 9.

    How do I do this? By default, Excel assumes the alphabet is "0, 1, ..., 9, A, B, ..., Z" (i.e., the numbers come before the letters).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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