+ Reply to Thread
Results 1 to 6 of 6

sort order of array elements into a matrix

  1. #1
    Registered User
    Join Date
    09-06-2018
    Location
    Germany
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    5

    sort order of array elements into a matrix

    Hi,

    I have the following problem. I want to put the ordered positions of one dimensional array elements in a two dimensional array. Here's an example:

    1d array:
    (A,C,D,B,C,E,C,A,K,B)

    2d array (every line represents a different letter in the following order: A, B, C, D, E, K)
    1 8 .
    4 10 .
    2 5 7
    3 . .
    6 . .
    9 . .

    How would you solve this? I have a very long code for this (because of problems with resizing two dimensional arrays with redim preserve, I have to transpose them first, where sometimes the second dimension gets lost, so that I have to add it again), but without the sorting. Maybe there is something easier.

    Thanks!

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: sort order of array elements into a matrix

    Personally, I'd use Dictionary/Collection to hold concatenated value of string position. At same time checking for column(s) required in result array.

    Then, use System.Collections.ArrayList to sort (see link below for article on the subject).
    https://excelmacromastery.com/vba-di...orting_by_keys

    Redim result array to suite and fill it from sorted dictionary.

    Since, I'm having issue getting past firewall on the site to post the code... see attached for sample code.
    Attached Files Attached Files
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: sort order of array elements into a matrix

    Quote Originally Posted by Irina Spalko View Post
    ... to put the ordered positions of one dimensional array elements in a two dimensional array ...
    Prosim vas, pozrite sa na to, try this:
    Please Login or Register  to view this content.
    Last edited by mjr veverka; 05-23-2019 at 05:11 AM.

  4. #4
    Registered User
    Join Date
    09-06-2018
    Location
    Germany
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    5

    Re: sort order of array elements into a matrix

    Quote Originally Posted by CK76 View Post
    Personally, I'd use Dictionary/Collection to hold concatenated value of string position. At same time checking for column(s) required in result array.

    Then, use System.Collections.ArrayList to sort (see link below for article on the subject).


    Thank you. Very interesting way to solve this. I'll look into it.

    Quote Originally Posted by porucha vevrku View Post
    Prosim vas, pozrite sa na to, try this:
    Thank you, although this code only places the items themselves in the matrix but not the position numbers of the items. I used the bubble sort as well.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: sort order of array elements into a matrix

    Quote Originally Posted by Irina Spalko View Post
    ... but not the position numbers of the items ...
    Yes, a small misunderstanding:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-06-2018
    Location
    Germany
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    5

    Re: sort order of array elements into a matrix

    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. Non-Array formula to Remove Duplicates and Sort in Ascending Order
    By bjnockle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-17-2018, 02:59 PM
  2. [SOLVED] Excel IsNumber Function treats array elements differently from range elements
    By Alan Beban in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-31-2018, 02:22 PM
  3. [SOLVED] Average of matrix elements using row and column conditions
    By Luis Ah-Hoy Jr. in forum Excel General
    Replies: 3
    Last Post: 06-09-2017, 10:42 AM
  4. Sort array formula results in descending order
    By OLLY-7 in forum Excel General
    Replies: 8
    Last Post: 12-19-2016, 02:47 PM
  5. [SOLVED] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  6. How to compute the inverse of a matrix with some complex elements
    By Annoushka42 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-05-2006, 08:10 PM
  7. [SOLVED] How to do matrix operation with complex number elements in Excel
    By Bernard Liengme in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 06:05 AM

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