+ Reply to Thread
Results 1 to 12 of 12

How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

  1. #1
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA as shown in attached excel?

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Unfortunately you need to break down the cell into its component parts, and then format the numerical elements so that they are the same length, otherwise it sorts numbers like text, which is what is causing you the problem.
    This formula will convert the string in one go (assuming there are always 2 alpha characters in positions 1 and 2
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And you can use this value to sort in the usual way

    In the attached workbook I have broken that formula down for you in separate columns which may be easier to follow!
    Last edited by Kevin#; 04-08-2016 at 01:14 PM.
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Hello london7871,

    Here is another approach with VBA. I have used the Macro Recorder which will hopefully make it easier for you to understand. You may play around with it and change your ranges to suit.

    Please Login or Register  to view this content.
    I have moved the Data Range down to start at Row3. All you now need to do is to hit on the "Click Me" - button in the attached sample Workbook below.

    HTH

    Regards.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Try this code
    Please Login or Register  to view this content.

  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: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    You could use a UDF in an extra column and sort by that:

    Row\Col
    A
    B
    C
    1
    Input
    Sort
    2
    SR4.2/10 SR04.02/10 B1: =padnum(A1, 2)
    3
    SR4.2/11 SR04.02/11
    4
    SR4.2/8 SR04.02/08
    5
    SR4.2/9 SR04.02/09


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

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Hello london7871,

    I have adapted the Code to allow for any length of Data in ColumnA. Please replace the Code in the sample Workbook in Post #3 with the Code below:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Regards.
    Last edited by Winon; 04-08-2016 at 02:00 PM. Reason: Added reset Code

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Hi London7871

    Here's another approach...

    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    How to sort different format as below as per attached excel:
    SR4.3/8,9; SR4.2/10,11,7+1,7A to SR4.2/7A,7+1,10,11;SR4.3/8,9 ?

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Hi london7871,

    You were offered you a couple of solutions to your original request, without you acknowledging any of them. I don't think I will be far off by saying, that members might be less inclined to try and help you again.

    Common courtesy could earn you some respect, if you at least thank one or more of the contributors to your original request, and then hopefully you may receive further assistance.

    In Post #8 you could add something like:

    Hi guys,
    Thank you for all your help. Sorry but could we expand it to "How to sort different format as below as per attached excel:
    SR4.3/8,9; SR4.2/10,11,7+1,7A to SR4.2/7A,7+1,10,11;SR4.3/8,9 ?"
    Thank you for your understanding.

    Regards.
    Last edited by Winon; 04-09-2016 at 11:45 AM.

  10. #10
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Sorry Winon and thanks for your help. I'll improve my asking skill.

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Hi london7871,

    Thank you.

    Please confirm if the numbers SR4.3/8,9; SR4.2/10,11,7+1,7A as per your new sample Workbook are the only values of interest, or may there be other variations?

    Regards.

  12. #12
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: How to sort SR4.2-10,11,8,9 to SR4.2-8,9,10,11 by VBA

    Please see attached excel for my actual case.
    Attached Files Attached Files

+ 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. Replies: 1
    Last Post: 04-16-2015, 06:29 PM
  2. Replies: 1
    Last Post: 03-04-2015, 02:57 PM
  3. [SOLVED] I have a sort macro. How to add script to preselect rows to sort based on column value?
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-09-2014, 02:25 AM
  4. Replies: 2
    Last Post: 01-15-2014, 09:31 AM
  5. [SOLVED] Query Multiple Web Pages> Sort For Specific Criteria > Save Lists of Sort in txt files
    By Tlandress in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-15-2013, 12:09 AM
  6. Replies: 4
    Last Post: 11-20-2012, 06:00 PM
  7. [SOLVED] Pls. reply Sort Data and copy to next coulmn when sort order chang
    By shital shah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2005, 10:05 AM

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