+ Reply to Thread
Results 1 to 7 of 7

Sort data in a different way

  1. #1
    Registered User
    Join Date
    09-03-2009
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    3

    Sort data in a different way

    Hi,

    I've the following sorted data in Excel (with the built in sort function).
    0216AA
    0216AA
    0216AA
    0216AA
    0216AA
    0216AA
    0225BB
    0225BB
    0225BB
    09036-0216AA
    09036-0216AA
    09036-0216AA
    09036-0216AA
    09036-0216AA

    The numbers represents products. The problem is that 0216AA and 09036-216AA are the same products. So after 0216AA have to come 09036-0216AA. How can I do this sort automatically instead of manually copy and paste.
    Is it possible using VBA?

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,963

    Re: Sort data in a different way


    One way is to use a helper column. For example, if your product codes are in column A, insert a new column B and enter the formula:
    Please Login or Register  to view this content.
    and copy down to the last row of the list. Then sort on column B
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    09-03-2009
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Sort data in a different way

    Thank you protonleah!
    But this only works if the product number consist of 6 characters after the hyphen. In some cases the product number consist of less or more characters. Is there a solution for this?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Sort data in a different way

    Yahu, I really think this kind of thing is a never-ending battle if allow it to start at all. Don't.

    ProtonLeah has the right idea. If you need your data sorted in a special way then you'll have to add a helper column of some kind and put the values in there that you want so they are permanently linked together. Once you've designed a workable "sorting column", you do all your sorting by that column.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,963

    Re: Sort data in a different way

    Please lookup FIND & SEARCH in Help. You can modify the previous formula with the results...

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sort data in a different way

    something like
    =TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",40)),10))
    but
    if you have say
    09035-0216AA
    09038-0216AA
    09036-0216AA
    09037-0216AA and also want it sorted on the stuff before the -
    so it goes
    0216AA
    0216AA
    0216AA-09035
    0216AA-09036
    0216AA-09037
    0216AA-09038
    0216AA-09039


    =IF(ISNUMBER(FIND("-",A1)),TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",40)),10))&"-"&LEFT(A1,FIND("-",A1)-1),TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",40)),10)))
    Last edited by martindwilson; 09-04-2009 at 08:00 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    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

  7. #7
    Registered User
    Join Date
    09-03-2009
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Sort data in a different way

    Thank you Martin! Your code is great. It's working as I want.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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