Excel VBA:添加到数组时参数不可选错误

时间:2017-04-11 22:35:18

标签: excel vba excel-vba

我遇到以下代码的问题。每当它到达最后一行时,它都会抛出错误“Argument Not Optional”,并且不会编译。我不知道它在谈论什么论点。

Option Base 1
Dim temp As New ProductionItem 'Production Item is a class that I made
Dim Arr() As Collection
ReDim Arr(5)
Dim coll As New Collection
coll.Add temp
Arr(1) = coll

1 个答案:

答案 0 :(得分:1)

只需要设置

Option Base 1

Sub fun()
    Dim Arr() As Collection
    ReDim Arr(5)
    Dim coll As New Collection
    coll.Add 1
    Set Arr(1) = coll
End Sub