3 回答
TA贡献1900条经验 获得超5个赞
您可以使用收藏集
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
TA贡献1839条经验 获得超15个赞
Jean-Francois指出,每个元素可以是长度可变的数组。我要补充一点,每个元素也可以是其他类型,而不必是数组。例如:
Dim c as New Collection
Dim a(1 to 5) as Variant
c.Add "a","a"
c.Add "b","b"
a(1) = 5
a(2) = Array(2,3,4)
set a(3) = c
a(4) = "abcd"
a(5) = Range("A1:A4").Value
然后可以根据每个子元素的隐式类型来引用各个子元素:
a(2)(1)= 3
a(3)(1)=“ a”
a(5)(2,1)=单元格A2中的内容。
- 3 回答
- 0 关注
- 545 浏览
添加回答
举报