Array With Multiple Sub Arrays - is it possible?

fat-tony

New Member
Joined
May 12, 2011
Messages
29
Hi Guys,

Got a fun new question about arrays today.

I have an array:

MainArray(1 to 25)

What I am hoping to get is the following:

MainArray(1 to 25).SubArray1(1 to 3, 1 to 10)
MainArray(1 to 25).SubArray2(1 to 6, 1 to 5)
MainArray(1 to 25).SubArray3(1 to 3, 1 to 5)
MainArray(1 to 25).SubArray4(1 to 4, 1 to 15)

I have it working with one Sub Array only at present:
Code:
Option Base 1

Private Type arrayType
    SubArray1() As String
End Type

Sub Array_Array()
    Dim TLArray(25) As arrayType
    For i = 1 To 25
        ReDim Preserve TLArray(i).SubArray1(3, 10)
    Next i
    For i = 1 To 25
       For x = 1 To 3
          For y = 1 To 10
              TLArray(i).SubArray1(x, y) = "Stuff Goes Here"
          Next y
       Next x
    Next i
End Sub
Opening this up for any advice and dicussion thanks.
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Not really clear to me what the issue is - can't you just add the other arrays to your Type declaration?
 
Upvote 0
Not really clear to me what the issue is - can't you just add the other arrays to your Type declaration?

Yeh thats the current way I was doing it which is why I posted that method to get the ball rollling with 1 sub array. The thread was more of forum for discussing how other people use Excel and VBA to achieve the same goal.
 
Upvote 0
Is there any reason why you would want to have subarrays instead of just having a three-dimensional array?

Code:
Sub Array_Array()
    Dim TLArray() As String
    For i = 1 To 25
        ReDim Preserve TLArray(25, 3, 10)
    Next i
    For i = 1 To 25
       For x = 1 To 3
          For y = 1 To 10
              TLArray(i, x, y) = "Stuff Goes Here"
          Next y
       Next x
    Next i
End Sub

You wouldn't even need to declare a type..
 
Upvote 0
By using a 1D array of a Type, you can redim preserve that array as you encounter more items. If you use a multidimensional array you can only redim the last dimension if you want to Preserve the contents.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top