+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    10-12-2006
    Location
    USA
    MS-Off Ver
    2007
    Posts
    10

    Sorting: How to get A2 come before A10

    Hi,

    I have a spreadsheet with a row that contains a certain code in string+number format. Example: (actually in random order, A4 may come before A1)

    A1
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9
    A10
    A11
    AA1
    AA2
    ....
    AA10
    AA11


    Then if I try to sort it sequentially, that is A1 A2 A3 ... A10 A11; It sorts like A1 A10 ... A11 A2 A20 .... this way.

    What can I do to make it sorted the way I want ?

  2. #2
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Sorting: How to get A2 come before A10

    Hi,

    the values you are sorting are text. The order for text sort is A1, A11, A2, etc. If you want a numeric sort, you either need to change your text values so the numbers have leading zeros

    A001
    A002
    A003
    A010
    A020

    or you need a separate column with only numeric values and sort the data based on that column.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  3. #3
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,477

    Re: Sorting: How to get A2 come before A10

    what does your real data look like?
    to get that to sort you need to make the numbers the same length
    eg
    A01
    A02
    A03
    A04
    A05
    A06
    A07
    A08
    A09
    A10
    A11
    AA01
    AA02
    then use that to sort by but method will vary according to data
    one way
    =SUBSTITUTE(A1,LOOKUP(9.99E+307,--MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890)),ROW(INDIRECT("1:"&LEN(A1))))),"")&TEXT(LOOKUP( 9.99E+307,--MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890)),ROW(INDIRECT("1:"&LEN(A1))))),"0000000")
    Last edited by martindwilson; 02-16-2010 at 07:26 PM.
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    10-12-2006
    Location
    USA
    MS-Off Ver
    2007
    Posts
    10

    Re: Sorting: How to get A2 come before A10

    adding leading zeroes is not currently (manually I mean, at least in current format) an option since there are more than thousand rows, unless I know any formula that does it.

    The number of string characters vary (from 1 to 6). Numbers do not have same format (that is not in 01 02 format, the actual data is in 1 2 3 .. 10 11 format).

    Any available options for me?

    I have added an extract from the spreadsheet. SetCode is the variable/column I want to sort in A1 A2 ..A10 format.
    Attached Files Attached Files
    Last edited by boka; 02-16-2010 at 07:23 PM.

  5. #5
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Sorting: How to get A2 come before A10

    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    10-12-2006
    Location
    USA
    MS-Off Ver
    2007
    Posts
    10

    Re: Sorting: How to get A2 come before A10

    tried this B1: =LOOKUP(9.99E+307,--MID(A1,1,ROW(A$1:INDEX(A:A,LEN(A1)))))

    I get #N/A in B column.


    I too noob in excel to know/read a vba function.

  7. #7
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Sorting: How to get A2 come before A10

    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    10-12-2006
    Location
    USA
    MS-Off Ver
    2007
    Posts
    10

    Re: Sorting: How to get A2 come before A10

    this works ....=SUBSTITUTE(A1,LOOKUP(9.99E+307,--MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890)),ROW(INDIRECT("1:"&LEN(A1))))),"")&TEXT(LOOKUP( 9.99E+307,--MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890)),ROW(INDIRECT("1:"&LEN(A1))))),"0000000")



    Thanks !!

  9. #9
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,477

    Re: Sorting: How to get A2 come before A10

    see attached it works !
    Attached Files Attached Files
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Registered User
    Join Date
    10-12-2006
    Location
    USA
    MS-Off Ver
    2007
    Posts
    10

    Re: Sorting: How to get A2 come before A10

    thanks a bunch .... ^^ (martindwilson) this formula worked.

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.2.0