+ Reply to Thread
Results 1 to 4 of 4

Question re Dynamic Arrays

  1. #1
    Registered User
    Join Date
    03-10-2004
    Posts
    55

    Question re Dynamic Arrays

    I've sought help on this fully 4 years ago and I still can't seem to get my bloody head around this.

    I've got a 1 dimensional array whose length will change depending on the population of a given range on a worksheet (think of 1 column).

    I need to set a second array with 3 columns for which I would like to a). populate the first column with values from the first array, b). populate the other two columns with numbers deriving from the numbers in this first column.

    So essentially I have array1 (a columnar array already populated) and array2 which I try to populate as follows (r1 below represents the length of array1)

    Please Login or Register  to view this content.
    But for whatever reason when I get to i = 2, I keep getting a 'Subscript out of Range' error.

    Does anyone know why this would happen? Have I incorrectly initialized array2? (if so, I've tried switching the populating indices for array2, I've tried initializing it as 1 to 3, 1 to 1, etc., but all to no avail).

    Any help would be tremendously appreciated.

    -Pete
    Last edited by VBA Noob; 07-09-2008 at 02:35 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Pete - I'm guessing the problem is that you can only apply Redim to the last dimension of an array. Perhaps explain what you're trying to achieve and/or a small sample workbook.

    Actually I don't think you need to place the Redim in the loop. Would something like this work?
    Please Login or Register  to view this content.
    Last edited by StephenR; 07-09-2008 at 02:46 PM.

  3. #3
    Registered User
    Join Date
    03-10-2004
    Posts
    55
    Hi Stephen,

    Thanks for the extra pair of eyes, your suggestion actually does solve my problem.

    I just sat out to write what I was trying to do extensively but then just realized that it wasn't as simple as what I was making out...if I have time, I'll write back with the bigger picture, but your help in the interim is extremely appreciated.

    Thanks!

    -Pete

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    I'm guessing the problem is that you can only apply Redim to the last dimension of an array.
    Stephen is, as usual, guessing well. To do otherwise would require shuffling all the elements of the array, instead of just adding space at the end.

+ 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