+ Reply to Thread
Results 1 to 3 of 3

Redim an array within an array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Question Redim an array within an array

    Can I redim an array that is held within an array?

    I have (for example) 3 worksheets, and from each one I want to load 2 columns into an array.
    However I also want (I think) those 3 arrays to be contained within one array so that I can step through them easily.

    The code below will not run, but might better show what I am wanting;

    const sources_qty As Long = 3
    Dim source_arrays() as Variant ' the array to hold the others
    Dim array1() as variant
    Dim array2() as variant
    Dim array3() as variant
    
    Dim index as Long
    Dim ws as Worksheet
    
    ' Assign the arrays into the 'grouping' array
    ReDim source_arrays(sources_qty)
    source_arrays(1)=array1
    source_arrays(2)=array2
    source_arrays(3)=array3
    
    ' Load the arrays from the sheets
    for index = 1 to sources_qty
        Set ws = ThisWorkbook.Worksheets(Choose(index,"MyFirst","MySecond","MyThird"))
        ' the line below should redim the array HELD in source_arrays(1) (ie. array1), to be the same size as the number of used rows on 'ws'
        ReDim source_arrays(1)....... ? ws.usedrange.rows.count
    next
    'more code
    I'm just not sure how to reference the array within an array in order to redim it, (if it is possible?)

    thanks
    Last edited by Phil_V; 08-17-2009 at 09:11 AM.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Redim an array within an array

    You would need to assign the array to a variable, redim and then load back into the container array. Based on that code though, I don't see the point in putting the dynamic arrays into the container array before you have populated them?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Redim an array within an array

    There is more to the actual code than this shows, but this example was the simplest way I could think to show what I was trying to achieve. Based on your reply on another thread as well I am going to rethink this now anyway

    Thanks again!

+ 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