+ Reply to Thread
Results 1 to 16 of 16

Sort data in specific alphanumerical order

  1. #1
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Sort data in specific alphanumerical order

    Hi all,

    I have to macro below which has been working great when sorting a list of items in a specific alphanumerical order. It works great when the sheet has a single list of items. The challenge I have now, is that I oftentimes have a sheet containing several lists of items. Attached sample book shows an example of what I'm talking about (To Be Sorted). The macro in its current state sorts based on an inserted column B (which is then deleted), but ALL content is then re-arranged. The result you can see it in Sheet1. What I've been doing to avoid such result, is cutting and pasting every list to its own sheet, run the macro, then cut and paste the resulting sorted list back to the main sheet, but it has become a time consuming process when I have close to 10 lists in the sheet.

    What I'm looking to achieve is this: I'd like to manually click on the first item of a list (for instance, A2, H2 or H11 in the sample sheet) to tell Excel where my list starts, then run a macro that sorts that specific list individually, without affecting the other lists within the sheet. My lists always have at least one empty column (and an empty row if there's more below) between them. (OR, if possible, it would be even better if Excel can find those cells where the lists start, since they will always be under the title "SKU").

    If you see the code, you'll notice I'm introducing a formula to sort based on its results, the reason I need this is so the items are sorted like first column, not as the second one in the sample below. However, if there's a better way to achieve this sorting, that would be even better!:

    BCP-3500 VS BCP-10315
    BCP-10315 VS BCP-34201
    BCP-34201 VS BCP-3500

    Thanks for any help!


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by axtryo; 05-01-2018 at 12:44 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Sort data in specific alphanumerical order

    Do you mean?
    Please Login or Register  to view this content.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Sort data in specific alphanumerical order

    Select TopLeftCell of table to be sorted.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 05-01-2018 at 03:07 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Hi Jindon,

    I apologize for late response, and thank you for your help, as usual.

    I tried the code, it worked well to keep the sort within the "current area", as needed. However, since my intent is to also sort lists that start and end at different locations, became obvious the code needs some adjustments (can't reference column "A" when the list is located at a different cell/column). My guess is it's all about setting the "Range" properly?

    The attached sample book contains 3 lists located randomly. Let's say I'd like to sort the one where the first record to be sorted is located at H11. How would the 'Range' be stated so Excel inserts the extra column, counts the rows to insert the formula, and then sorts on the records contained?

    I tried to come up with something, but the below code is as far as I could go (assuming I click on the first record I need sorted so Excel 'knows' where my list starts). Pretty sure there might be a better way to start with? ...

    Please Login or Register  to view this content.
    Thank so much for your help.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Sort data in specific alphanumerical order

    Did you even bother to test the code I posted ?

  6. #6
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Hi Bakerman2

    I appreciate you took the time to help me.

    I tried your code and really liked the 'InputBox' command to set the range to be sorted. However, I got an error message saying "Run-time error '1004'" The sort reference is not valid. Make sure that it's within the date you want to sort, and the first 'Sort By box isn't the same or blank."

    I have no idea what that means to be honest, but the macro stopped when trying to run this line:
    Please Login or Register  to view this content.
    Not sure how to fix that?

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Sort data in specific alphanumerical order

    Start the code and select cell H10 of left bottom table to be sorted.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Bakerman,

    I tried the code with the 3 tables contained in the sample book but still get the same error message. I'm using Excel 2016. Not sure if that might be a reason behind the code not working? ...

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Sort data in specific alphanumerical order

    My code is fully based on your file/code.
    If range is different, neet to see your file.

    I' out at the moment, so reply will be late.

  10. #10
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Hi Jindon,

    Thanks for your response. The first message of this thread contains a sample book with 3 tables, each located randomly. If you please download that file, you'll see what I'm talking about.

    No problem for a late response. Your help is highly appreciated.

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Sort data in specific alphanumerical order

    I can't test but does this help ?
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Bakerman,

    YES! The code works as wanted. I'll do further testing tomorrow at work and will come back to report on that.

    Thanks!

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Sort data in specific alphanumerical order

    Do you mean like this?
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Bakerman,

    I'm finally back. Sorry for delayed response. I tested your code extensively at work. It works as intended. However, I'm not sure if due to being using Excel 2016, but it happened sometimes, that it didn't sort the data as expected. In fact, it didn't do anything at all. The weirdest part is that I got no error message of any kind. Once a sheet got, let me use the word, "altered", there was no way the code did anything. Now, I'm not saying your code has an issue. I actually have no idea why that happens, but that lead me to a question.

    The main reason I'm inserting the formula "=LEFT(RC[-1],FIND(""-"",RC[-1])-1)&LEN(RC[-1])-3", is because I need the data sorted in a specific alphanumerical order, and not in the built-in sort in Excel. Since this post was intended to solve sorting within a certain area, I'll go ahead and post a new thread to address that.

    In the meantime, I'm adding reputation to you and giving you a BIG thank you for your help

  15. #15
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Jindon,

    The code you posted actually finds the SKU and does sort the data, however, it sorts it in the Excel built-in sort, and not in the alphanumerical sort I actually need it. Since the goal of this post has been achieved, I'm posting a new thread to ask specifically about the best way to achieve the needed sort. As I mentioned to Bakerman, seems like the code sometimes get ignored and I have no idea why.

    I'll add a link to the new post here.

    In the meantime, thanks for your help!

  16. #16
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Sort data in specific alphanumerical order

    Bakerman and Jindon,

    I started a new thread that I tittle the same as this one (didn't realize it until I hit the 'post' button!). Sort data in specific alphanumerical order. If you're so kind to take a look at it, it will be highly appreciated.

    Thanks!

+ 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. Sort comma separated string, but in specific order
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2017, 08:53 AM
  2. [SOLVED] Sorting alphanumerical column in numeric order
    By thadacto in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-29-2017, 06:10 AM
  3. [SOLVED] sort order according to columns specific in another worksheet cells
    By raj soni in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-27-2015, 09:42 AM
  4. [SOLVED] Sort 3 textboxes to get an order for a specific formula
    By stielo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-27-2015, 10:24 AM
  5. [SOLVED] Sort specific visible sheets in an order according to cells in each sheet
    By Comisar in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-14-2013, 06:57 PM
  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