Closed Thread
Results 1 to 4 of 4

Custom Sort VBA Problem

  1. #1
    Forum Contributor
    Join Date
    07-21-2018
    Location
    London, England
    MS-Off Ver
    Excel for Mac Version 16.15
    Posts
    117

    Custom Sort VBA Problem

    Hello!

    I have put together some VBA code to custom sort some data (below). However, I'm getting unexpected results and I don't know why.

    Please Login or Register  to view this content.
    Screenshot 2019-04-11 at 10.49.53.png

    In my custom sort, UK sizes should appear in ascending order (UK 4, UK 6, UK 8, UK 10, UK 12, UK 14). However, as you can see from the image, they don't appear in this order.

    Is anyone able to help me figure this out? I have attached my workbook for reference.

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Custom Sort VBA Problem

    The data is sorting correctly. The Size is the last key to be sorted. Maybe you should sort by Size before by SKU, or even earlier depending on the precise order.

    But I question why you are adding sort keys every time with the macro. In fact every time you run the macro you just add another set of sort keys which repeat the first set. This is wasteful of resources.

    Why can't you manually sort the data as you want and then just have the macro perform the sort without any of the .AddKey stuff.

    If you do want to add keys for some strange reason then at least have the macro first delete what's there.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

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

    Re: Custom Sort VBA Problem

    Your sort list didn't actually match your data properly, and you should clear the existing sort before adding new fields, so:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Custom Sort VBA Problem

    Why are you duplicating threads. WIth 91 posts you should know better. This post will now be closed and you should continue in your other thread.

    Thread Closed.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using custom sort orders with Range().sort
    By WestWindsDemon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2018, 03:52 PM
  2. [SOLVED] VBA to custom sort on custom list
    By GregStewartPTC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2018, 12:54 PM
  3. [SOLVED] Custom sort without custom list
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-12-2016, 02:10 PM
  4. Challenged: ascending sort within custom sort
    By jhren in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2013, 12:35 PM
  5. Custom List Sort - A struggling problem
    By rakesh_sss in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-29-2012, 02:50 AM
  6. Custom sort order problem
    By mfmcclellan in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-04-2012, 05:05 PM
  7. [SOLVED] 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

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