+ Reply to Thread
Results 1 to 4 of 4

Sorting a Multi-Dimensional Array by Value, Highest to Lowest [Excel, VBA Only]

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Sorting a Multi-Dimensional Array by Value, Highest to Lowest [Excel, VBA Only]

    So I have a table of values:

    Col A Col B Col C
    Row 1 23410 7000.00 6939.45
    Row 2 23397 15000.00 11244.51
    Row 3 27060 4000.00 3524.78

    I need to be able to sort the values (up to 10 eventually) using an multidimensional array by Column B. The code will eventually be in a UserForm (and thus cannot rely on a spreadsheet sort).

    The following code works on two conditions: 1. Only 3 rows of data (need up to 10) & 2. If it is in the order as shown (needs to be any order)

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Sorting a Multi-Dimensional Array by Value, Highest to Lowest [Excel, VBA Only]

    Hi lloydgodin,

    I have approached problems like this by converting all the numbers to strings, all having the same number of digits before and after the decimal point.

    You might want to try something like the following:
    Please Login or Register  to view this content.
    Lewis
    Last edited by LJMetzger; 03-23-2015 at 04:08 PM. Reason: Changed sort from ascending to descending; Lewis can't read.

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Sorting a Multi-Dimensional Array by Value, Highest to Lowest [Excel, VBA Only]

    Lewis,

    Sorry for the late reply. I was out of the office yesterday. I took the code you used to sort and was able to get it to work. I was able to do it without converting the numbers. Here is a copy of the working code:

    Please Login or Register  to view this content.
    Thank you so very much for your help.
    Last edited by lloydgodin; 03-25-2015 at 09:25 AM. Reason: forgot to post my gratitude

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Sorting a Multi-Dimensional Array by Value, Highest to Lowest [Excel, VBA Only]

    You could use something like this.
    Note that getting the array from and writing it to a worksheet is just for testing purposes. The array can be gotten any way (as long as it is a 1-based two dimensional array).

    The keyColumn and Descending arguments can be adjusted to your liking.
    This uses a bubble sort but the "sort row numbers" approach can be used with any kind of sort.
    The "build SortedArray using arrRows as a guide" explains the concept behind this.

    Please Login or Register  to view this content.
    Last edited by mikerickson; 03-25-2015 at 09:46 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. [SOLVED] Sorting an Array by Highest to Lowest [Excel 14, VBA Only]
    By lloydgodin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2015, 09:26 AM
  2. Set up a multi-dimensional array
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-04-2013, 04:28 AM
  3. Load excel range into multi dimensional array
    By Rishi Dhupar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2006, 11:55 AM
  4. [SOLVED] Multi-Dimensional Array Let & Get
    By Trip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2005, 04:05 PM
  5. [SOLVED] Re : Excel Sorting a 2-Dimensional Array
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-03-2005, 12:06 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