首页 > 解决方案 > excel vba - 创建一个包含数组条目的集合

问题描述

有没有办法用数组的条目创建集合?
我有一个包含三个条目的数组:

dim components(1 to 3)
components(1) = "A"
components(2) = "B"
components(3) = "C"

现在我想遍历数组并为每个组件创建一个集合:

for each c in components
    dim c as new collection
next

但这会引发错误。

谢谢

标签: vbaexcel

解决方案


如果您需要多个集合,请创建集合集合。您不能将多个集合压缩到变量“c”中。

for each c in components *add new subcollection to a main collection* next


推荐阅读