+ Reply to Thread
Results 1 to 15 of 15

VBA to Custom Sort Data Based on Referenced List

  1. #1
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    VBA to Custom Sort Data Based on Referenced List

    Sort Example.xlsxHi All,

    First time poster, but a long time beneficiary of this board's knowledge. I have a seemingly simple issue...

    I have data in Sheet "Schedule" in range A8:C160 (including column headers), but note the length (rows) of the range is dynamic.

    A8 = Customer
    B8 = Load Time
    C8 = Delivery Time

    Columns B & C are formatted as h:mm:ss AM/PM, but Column B also includes text..."PRELOAD"

    I would like a macro to sort the data based on column B, but the sort must follow a specific order, which is listed in Sheet "TimeSort", range A1:A50 (including header).

    The custom order basically has "PRELOAD" sorting at the top, then sorting everything else chronologically starting at 6:00am.

    The desired outcome would sort the range based on column B as follows...PRELOAD, 6:00:00 AM, 8:00:00 AM, 12:00:00 PM, 5:30:00 AM

    Example is attached (desired sort is reflected).

    Any help is very appreciated!

    Thanks.

  2. #2
    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: VBA to Custom Sort Data Based on Referenced List

    Hi Kehoth01

    Welcome to the Forum!!!

    Can you show us your expected results based on your Sample File?
    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.

  3. #3
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: VBA to Custom Sort Data Based on Referenced List

    Hi Jake,

    I reattached my file with the data unsorted, as well as with it sorted in the desired order.

    Does this help you understand my issue?

    Best,
    Tommy
    Attached Files Attached Files

  4. #4
    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: VBA to Custom Sort Data Based on Referenced List

    Hi Kehoth01

    Not sure
    Does this help you understand my issue?
    Try this...let me know where it's failing.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: VBA to Custom Sort Data Based on Referenced List

    I am getting a Run-time error 1004.

    Debugging puts me at line

    Application.AddCustomList Sheets("TimeSort").Range("Sort_Me").Value
    To restate my question, I want my range to sort on Column B, but I want the sort to start at "PRELOAD", then go chronologically starting at 6:00 AM, 7:00 AM, etc

  6. #6
    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: VBA to Custom Sort Data Based on Referenced List

    Hi Tommy

    Sorry about that. Forgot to tell you, need to add a Named Range called Sort_Me. It's Refers To is
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Do you know how to do that?

    If not, I can have the Code create the Named Range.

  7. #7
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: VBA to Custom Sort Data Based on Referenced List

    Jaslak,

    (Misread that as Jake earlier).

    Thanks! That completes the my desired sort, but it's crashing the file after running.

    I think I've heard about this issue with excel 2010 or newer and creating custom lists via VBA, but not sure of the solution.


    Thoughts?

  8. #8
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: VBA to Custom Sort Data Based on Referenced List

    I moved the .Sort.SortFields.Clear command to just before Application.DeleteCustomList... command.

    That seems to have solved the problem and aligns with some other posts with this issue.

    Thanks for the help!

  9. #9
    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: VBA to Custom Sort Data Based on Referenced List

    Hi Tommy

    Post your most recent File with Code...I'll run it in 2010...see if I can duplicate the issue.

    Edit: Tommy, you seem to have reconciled the 2010 Issues...please Post your Code and /or File so we can see your adjustments to the Code...It'll benefit us all.
    Last edited by jaslake; 02-17-2014 at 08:00 PM.

  10. #10
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: VBA to Custom Sort Data Based on Referenced List

    One last thing...how do I mark this as solved?

  11. #11
    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: VBA to Custom Sort Data Based on Referenced List

    Hi Tommy

    Please post your 2010 resolution for our benefit.

  12. #12
    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: VBA to Custom Sort Data Based on Referenced List

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  13. #13
    Registered User
    Join Date
    02-12-2014
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: VBA to Custom Sort Data Based on Referenced List

    Modified code below...


    Please Login or Register  to view this content.

  14. #14
    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: VBA to Custom Sort Data Based on Referenced List

    You're welcome...glad I could help.

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

  15. #15
    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: VBA to Custom Sort Data Based on Referenced List

    Hi Tommy

    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)

Similar Threads

  1. Data Validation based on list & sort & separate
    By Thunderer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2014, 10:47 PM
  2. Sort list of data taken from another source based on certain criteria
    By Scott_88 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-28-2013, 10:19 AM
  3. Table unable to sort referenced data
    By Cuckooguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2012, 02:21 AM
  4. Excel sort by Fill Color by custom list sort
    By Dash4Cash in forum Excel General
    Replies: 2
    Last Post: 07-29-2005, 06:05 PM

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