+ Reply to Thread
Results 1 to 9 of 9

Sorting variants (two dimensional)

  1. #1
    Registered User
    Join Date
    01-06-2014
    Location
    Brno
    MS-Off Ver
    Excel 2007
    Posts
    7

    Sorting variants (two dimensional)

    Hi there,

    is there an easy way to sort variants? I ve searched the internet and it seems that sorting works just with ranges
    Please Login or Register  to view this content.
    I have variant M with 20 rows and 4 columns and want to sort the rows according to the fourth row (from the smallest to the largest).
    I tried analogical things such as:

    Please Login or Register  to view this content.
    which does not work.
    I do not want to believe that VBA does not have any internal way (function) to solve variants sorting since it should be quite casual thing..

    Moderator note: I have added code tags for you. Please refer to our rules on posting.
    Last edited by alansidman; 02-06-2014 at 09:59 AM. Reason: code tags added per rule 3

  2. #2
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Sorting variants (two dimensional)

    look at
    createobject("System.Collections.Arraylist") and CreateObject("System.Collections.SortedList")
    or so
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    01-06-2014
    Location
    Brno
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Sorting variants (two dimensional)

    thank you, however as I have no experience with what you described, although I am searching I cannot figure out what it means. Could you please specify little bit more what I should do? :-)

  4. #4
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Sorting variants (two dimensional)

    how does you data look like ?
    Do you have an example.

  5. #5
    Registered User
    Join Date
    01-06-2014
    Location
    Brno
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Sorting variants (two dimensional)

    It is numerical data in the two dimensional variant, in fact it is not important what it looks like, however here is the example:

    Sub Showingexample()

    Dim M As Variant
    ReDim M(1 To 20, 1 To 4)
    For i = 1 To 20
    For j = 1 To 4
    M(i, j) = Sin(i * j)
    Next j
    Next i

    '??? M.sort ????? here I need to sort the data according to the fourth column

    End Sub

    If the data was written on a worksheet, I could work with sort.range which works fine, but I need to keep the data in the matrix, no way to write them out onto a sheet.

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Sorting variants (two dimensional)

    Welcome to the forum.

    Pls take some minutes to read forum rules.

    In your first post there is a note from a Moderator. Don't ignore this one and of course no Moderator request in the future.!

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  7. #7
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Sorting variants (two dimensional)

    mancubus

    Your post does not comply with Rule 7 of our Forum RULES. Please do not ignore requests by Administrators, Moderators and senior forum members regarding forum rules.

    If you are unclear about the request or instruction then send a private message to them asking for clarification. Do not post a reply in a thread where a moderator has requested an action that has not yet been complied with e.g Title change or Code tags...etc

  8. #8
    Registered User
    Join Date
    01-06-2014
    Location
    Brno
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Sorting variants (two dimensional)

    Thank you very much indeed! You helped me a lot. This apparantly works as it should.

    By the way - does this code also allow multiple sorting? I mean for example sorting primarily according to the fourth column, secondly according to the second column and then for example according to the third column? Is it general in this way?

  9. #9
    Registered User
    Join Date
    10-11-2011
    Location
    FB Republic
    MS-Off Ver
    2016
    Posts
    36

    Re: Sorting variants (two dimensional)

    sorry fotis.
    a quick read of posts made me miss your request.




    you're welcome GeorgeIII.

    re-read the post #6 by fotis and correct your post #5 by adding CODE tags around the code you posted.
    Last edited by mancubus; 02-07-2014 at 08:34 AM.

+ 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. Variants look the same but report being different -- how are they different?
    By GJL65 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-10-2012, 11:23 AM
  2. Sorting Alg for 2 dimensional string array
    By mrosendal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2011, 01:35 AM
  3. Creating a 2-dimensional array from a 1-dimensional list
    By guywithcamera in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-27-2008, 06:34 PM
  4. Use of Variants
    By rwgrietveld in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-14-2008, 08:44 AM
  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

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