+ Reply to Thread
Results 1 to 11 of 11

How to sort Single Letters before Double Letters

  1. #1
    Registered User
    Join Date
    09-09-2008
    Location
    USA
    Posts
    4

    How to sort Single Letters before Double Letters

    I need to be able to sort a column by letters going from A-Z then AA-ZZ. The problem is, I can only get Excel to sort alphabetically so AA comes before B and C or sorting gives me results like A B CC D EE G etc.

    Is there a way I can sort a column as single letters first then double letters (AA, BB, etc) alphabetically?

    Any help would be greatly appreciated.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    if it's only a single letter or double letter in that column, then perhaps you can use a helper column...

    So if those letters are in Column A, starting at A2 then try this formula in another column:

    =COLUMN(INDIRECT(A2&1)) copied down

    Then sort by the helper column....
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Hello Vittorio

    Your formula may fail unless the OP is using xl2007. Another possible helper formula could be:

    =SUMPRODUCT(CODE(MID(IF(LEN(A2)<2," "&A2,A2),{1,2},1))*{100,1})

    and copied down. Then Sort by this helper column.

    Richard
    Last edited by Richard Schollar; 09-09-2008 at 11:24 AM.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Hi Richard,

    How would it fail? I tested it in 2003 and it seems to work.

  5. #5
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    No ZZ1 cell in xl2003

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Good Point... didn't think of the column number limit....

    Thanks Richard.

  7. #7
    Registered User
    Join Date
    09-09-2008
    Location
    USA
    Posts
    4
    Quote Originally Posted by NBVC View Post
    if it's only a single letter or double letter in that column, then perhaps you can use a helper column...

    So if those letters are in Column A, starting at A2 then try this formula in another column:

    =COLUMN(INDIRECT(A2&1)) copied down

    Then sort by the helper column....
    That worked perfectly! Thanks!!!

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    A little more simplistic.... but this should do too.

    =IF(LEN(A2)=1,CODE(A2),CODE(LEFT(A2,1))+CODE(RIGHT(A2,1)))

  9. #9
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Sorry to be a pain Vittorio, but again you would need to adjust your formula in a very minor way:

    =IF(LEN(A2)=1,CODE(A2),CODE(LEFT(A2,1))*100 +CODE(RIGHT(A2,1)))

    this stops YY appearing above ZA

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Ok, I better end this one before I embarrass myself (if I haven't already)... thanks for pointing those out to me Richard. Good Eye.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Why not just =RIGHT(" " & A2, 2)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Converting Latitude/longitude to OSGB grid ref
    By Greenspan in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-10-2020, 12:43 PM
  2. Is there a way to clear all variables after a loop?
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-12-2008, 11:34 AM
  3. derivatives of a cubic spline
    By johnboy12 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-20-2008, 02:49 AM
  4. Invalid procedure call or argument
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2007, 06:01 AM
  5. New to writing macros
    By ynnod in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-06-2007, 10:20 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