# sort order of array elements into a matrix

1. ## 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. ## 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.

3. ## Re: sort order of array elements into a matrix

Originally Posted by Irina Spalko
... 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.``

4. ## Re: sort order of array elements into a matrix

Originally Posted by CK76
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.

Originally Posted by porucha vevrku
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. ## Re: sort order of array elements into a matrix

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

6. ## Re: sort order of array elements into a matrix

Thank you!

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

#### 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