您可以使用收藏集Public Sub Test() Dim list As New Collection Dim i As Integer, j As Integer Dim item As Collection For i = 1 To 10 Set item = New Collection For j = 1 To i item.Add "Kid" & CStr(i) & "Toy" & CStr(j) Next j list.Add item Next i Debug.Print "Kid 4, Toy 2 = " & list(4)(2)End Sub哪个输出 Kid 4, Toy 2 = Kid4Toy2
Jean-Francois指出,每个元素可以是长度可变的数组。我要补充一点,每个元素也可以是其他类型,而不必是数组。例如:Dim c as New CollectionDim a(1 to 5) as Variantc.Add "a","a"c.Add "b","b"a(1) = 5a(2) = Array(2,3,4)set a(3) = ca(4) = "abcd"a(5) = Range("A1:A4").Value然后可以根据每个子元素的隐式类型来引用各个子元素:a(2)(1)= 3a(3)(1)=“ a”a(5)(2,1)=单元格A2中的内容。