+ Reply to Thread
Results 1 to 12 of 12

Sorting Issue

  1. #1
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Sorting Issue

    Hello,

    I have been trying to solve an issue I have with how excel sorts my information so hopefully you gurus will be able to help me out. I have looked all over the web trying to find a solution and I can't seem to figure it out.

    Attached is a spreadsheet that is a good example of what I am trying to accomplish. To give a little idea of why I need to sort in this way the numbers are part numbers in a warehouse and we are moving to a new warehouse so I need to be able to sort this list so that it is in the same order as the parts are in on my shelves so we now how to space the parts on the shelves.

    If you go to row 56 you will see where there is an issue SBDS1464 is before SBDS737 where as on my shelf the order they are in is by the prefix first then by the root in ascending order so obviously 737 is way before 1464 and some of them also have a suffix and the way we handle those is for example on my shelf if we had SBDS737, SBDS737T and SBDS738 they would be in that order exactly. Then after we are all the way through SBDS prefix it goes to SBES and then by ascending order by the root number again and so on and so forth through all of the prefixes.

    I am sorry if this doesn't make much sense if something is confusing let me know and I will do my best to clarify. Normally I would just do it manually as a normal sort gets it kind of close but for all of my lines the report will be thousands of lines long and it will take forever.

    Thanks in advance the the help I appreciate it.

    Kelly
    Attached Files Attached Files
    Last edited by Kellypeterson; 01-19-2012 at 08:45 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: Sorting Issue

    You could use =LEFT(A1,4) and =RIGHT(A1,LEN(A1)-4) or just Text to Columns (fixed width) to split the code into two columns. Then sort on the "numeric part.

    Would that give youwhat you want?

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Sorting Issue

    That almost worked except for the ones with a suffix it sorted all of them at the end rather then mixed in.

  4. #4
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Sorting Issue

    Also in my example all of the part numbers have a 4 letter prefix but in reality my prefixes vary in length.
    Is there a way to if you have a string say abcd1235ef to tell excel to split that into abcd 1235 ef? The hard part is that the prefix root and suffix vary in length so it need to be able to split text number then text not a set number of characters.
    Last edited by Kellypeterson; 01-19-2012 at 06:34 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Sorting Issue

    You could use a UDF that expands the numeric part:

    Please Login or Register  to view this content.
    Then sort by the second column.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Sorting Issue

    I look at that and I see what you did for the most part but the question I have is with the prefix that is text will it still work even if the prefixes are different lengths throughout the spreadsheet? Also how will it handle the ones with a suffix? I would just try and it and see but that is the third problem I am not totally sure how to do it.. Sorry I am not very good with this advanced stuff as I have never done it before but I would love to learn.

  7. #7
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Sorting Issue

    This looks like it would do what I need but I can not get it to run it errors out... Any ideas what would cause it to error out I am not very good with VBA. http://www.ozgrid.com/VBA/sort-alphanumeric.htm

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: Sorting Issue

    In Excel, press Alt-F11 to open up the VB Editor
    Select Insert | Module
    Copy and paste the code for the User Defined Function into the newly created module.

    Back in Excel, in a cell in Row 1, type =PadNum(A1,4) as shown above. Copy down.

    Sort on the new column.


    Regards, TMS

  9. #9
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Sorting Issue

    Ok that is very close the only issue I can see is I need it to sort based on the length of the numeric part as well. So for example if I have SBK9081 and SBK90685 it currently puts SBK90685 before SBK9081.

    Thank you for the help and being so patient with me

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: Sorting Issue

    Change the 4 to 5: =PadNum(A1,5) ... or 6 even, if you might have six digit numbers


    Regards

  11. #11
    Registered User
    Join Date
    01-19-2012
    Location
    Salt Lake City, Utah, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Sorting Issue

    That worked like a charm! Thank you so much! I will make sure to do my best to contribute in areas where I have a better understanding!

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: Sorting Issue

    Well, the credit goes to shg ... it was, after all, his UDF. I just helped tweak the fine detail.

    But, thanks for the rep.

+ 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