+ Reply to Thread
Results 1 to 6 of 6

Using two custom sort lists in macro.

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Using two custom sort lists in macro.

    This is somewhat related to a post I had submitted previously but a bit more complex https://www.excelforum.com/showthread.php?p=2139259.

    I have following code, which sorts data if user "double clicks" on cells A1, B1, C1, D1, or E1.

    If the user "double clicks" on cell D1, I want to sort by column D using following custom list:
    AA1, AA2, AA3, A1, A2, A3, ZZ1, ZZ2, ZZ3, Z1, Z2, Z3

    If the user "double clicks" on cell E1, I want to sort by column E using following custom list:
    AAA+, AAA, AAA-, AA+, AA, AA-, A+, A, A-, ZZZ+, ZZZ, ZZ+, ZZ-, Z+, Z, Z-

    The issue I seem to be encountering is that I can’t use more than one custom list (e.g., if I use the column D sort list for column D, column E is also using the same list). I can’t seem to apply individual lists to each column.

    Would I need to “hardcode” the lists in my macro? In suggestions are appreciated. Thanks.

    Please Login or Register  to view this content.
    Last edited by maacmaac; 08-05-2009 at 12:05 AM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Using two custom sort lists in macro.

    You can hardcode the list in the macro. For example, I created a custom list in the Sorting screen, then recorded a macro of me sorting column A by that custom sort list. In Excel 2007 this is what it recorded:
    Please Login or Register  to view this content.
    This code will not work in Excel 2003 or 2000, so I suggest you do what I did and record the steps, then modify your code to include the custom sort. Since I don't have 2003 any longer, I can't test, but it might be as simple as updating
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: Using two custom sort lists in macro.

    Getting a compile error "Named argument not found" with:
    Please Login or Register  to view this content.
    Is there another arugument I should try? Thanks

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Using two custom sort lists in macro.

    As I said, the 2007 code won't work in 2003, so try recording a macro of you manually sorting the data and using the custom sort list, then review the new macro for that argument.

    Here's an example of someone else's custom sort list: http://www.mrexcel.com/forum/showthread.php?t=34939
    Last edited by Paul; 08-04-2009 at 02:32 PM. Reason: added link to example

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Using two custom sort lists in macro.

    Try this:
    1. Add the following to the ThisWorkbook module:
    Please Login or Register  to view this content.
    2. Add a new module and add these two functions to it:
    Please Login or Register  to view this content.
    then adjust your double-click code to this:
    Please Login or Register  to view this content.
    and see if that works for you.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: Using two custom sort lists in macro.

    Thanks to Paul and Romperstomper for useful advice. I ended up using romperstomper's suggestion but found some very useful information in the post that Paul had provided.

+ 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