+ Reply to Thread
Results 1 to 5 of 5

Defining Variable 2D array?

  1. #1
    Registered User
    Join Date
    11-09-2011
    Location
    San Diego
    MS-Off Ver
    Excel 2007
    Posts
    42

    Defining Variable 2D array?

    Hello Guru's! I am having a bit of an issue defining a variable 2d array. After searching around for a while and reading others posts I am stumped. Basically, my code works fine if I define the size of the 2d array up front, but if I try to leave the dimensions of the array open from the beginning the code errors out.

    Here is my code so far:
    Please Login or Register  to view this content.
    So as you can see right off the bat I define the dimensions of the array as 20 by 2, but is there a way to modify this so that the initial dimension of the array is left variable? I realize I can redim the array down the line in the code once I determine the final x value, but can it be done up front similar to a one dimension array? For instance I have this code previously used to build a 1d array of unique values:

    Please Login or Register  to view this content.
    how do I accomplish a similar redim of a 2d array with my code?
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    06-19-2012
    Location
    Canada Eh
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    40

    Re: Defining Variable 2D array?

    I don't see why you can't ReDim whenever or wherever you want. I can't really help you with the how-to part because I don't know how you would declare what the dimension should be at any point in your code but I know that you CAN ReDim any time.
    EF killed Mordred

    46 & 2 is just ahead of me!

  3. #3
    Registered User
    Join Date
    11-09-2011
    Location
    San Diego
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Defining Variable 2D array?

    So I have already tried something like this:

    Please Login or Register  to view this content.
    But I get an error that the array as already been dimensioned?

  4. #4
    Registered User
    Join Date
    11-09-2011
    Location
    San Diego
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Defining Variable 2D array?

    ok so now I found a post that states you can only redim the outer bound of the 2D array? Any one to confirm that for me?

  5. #5
    Registered User
    Join Date
    11-09-2011
    Location
    San Diego
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Defining Variable 2D array?

    here is the solution:

    Please Login or Register  to view this content.
    I had to flip the array, and then I was able to redim the outer dimension without a problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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