+ Reply to Thread
Results 1 to 8 of 8

Dynamic two dimensional array

  1. #1
    Registered User
    Join Date
    07-04-2019
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    8

    Dynamic two dimensional array

    This functions input is an range and the output are an array of row numbers, it only returns those rows which has same value two or more times, aka duplicates + 1 occurrence.
    As a one dimensional array it works fine, but I also want to add how many occurrence there are for each row, so i'm trying to transform the script to a dynamic two dimensional array (tempArray2).
    But I can't get it work. I read somewhere that it's only possible to redim the last dimension, therefore "ReDim Preserve tempArray2(t)".
    I get "subscript out of range" on row 12. Any pointers? Is it even possible?

    Please Login or Register  to view this content.

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

    Re: Dynamic two dimensional array

    Apart from everything else, there is no one "End If" clause.

  3. #3
    Registered User
    Join Date
    07-04-2019
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    8

    Re: Dynamic two dimensional array

    The missing 'End if' is just a typo, it's exists in my code, so that's not the issue.
    Change the redim to...
    Please Login or Register  to view this content.
    ...makes it work. But then it's not dynamic.

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    1,706

    Re: Dynamic two dimensional array

    Why don't you create a two-dimensional array right away/from the beginning ?
    Can you present the appearance/layout of the data on which this function works ?

    If "Dim Preserve ..." works inside a loop, this is dynamic ... (?)
    Last edited by porucha vevrku; 01-31-2020 at 07:43 AM.

  5. #5
    Registered User
    Join Date
    07-04-2019
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    8

    Re: Dynamic two dimensional array

    I found a flaw in my script, I have misunderstood how to fill the array, here is a more correct code.
    But main issue still remains, how to redim?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    1,706

    Re: Dynamic two dimensional array

    Where are the other "Case" and "End Select" ?

  7. #7
    Registered User
    Join Date
    07-04-2019
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    8

    Re: Dynamic two dimensional array

    Quote Originally Posted by porucha vevrku View Post
    Why don't you create a two-dimensional array right away/from the beginning ?
    Can you present the appearance/layout of the data on which this function works ?

    If "Dim Preserve ..." works inside a loop, this is dynamic ... (?)
    Well, it works if I start with
    Please Login or Register  to view this content.
    The problem is that I don't know how many rows(first dimension) there will be, so I don't understand/see how I write that code.

    The data would look this
    Attachment 660491
    And the input to the function would Range(A2:A5). The expected outcome will be [3, 2] (line 3, two times)

  8. #8
    Registered User
    Join Date
    07-04-2019
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    8

    Re: Dynamic two dimensional array

    Quote Originally Posted by porucha vevrku View Post
    Where are the other "Case" and "End Select" ?
    Also typo, since they are not part of the problem I have cleaned them to make it more readable, it back fired this time. =)

    Please Login or Register  to view this content.

+ 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] have 1 dimensional array, trying to create a 2 dimensional array, runtime 9
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2019, 07:03 AM
  2. Help converting one-dimensional array to multi-dimensional array
    By puzzlelover22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 06:48 AM
  3. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  4. Help with Declaring a dynamic 2 dimensional array
    By gablet in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-01-2015, 01:39 PM
  5. [SOLVED] Add to a two dimensional dynamic array based on a condition - redim preserve
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2014, 04:46 AM
  6. [SOLVED] Need help on Basic Two Dimensional Dynamic Array
    By chrixton in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-02-2014, 08:07 PM
  7. Dynamic 2 dimensional array in VBA class
    By dlx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2010, 09:20 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