我正在尝试将数组传递给集合,但我似乎无法填充该集合。
Public Function CreateCol(ws As Worksheet, ary, col As collection)
Dim rng As Range, collect As collection
Dim y, skey, svalue
On Error Resume Next
'populate fund list
For y = LBound(ary) To UBound(ary)
If ary(y) <> "" Then
skey = Trim(ary(y))
svalue = WorksheetFunction.SumIf(ws.Range("A:A"), ary(y), ws.Range("P:P"))
collect.Add svalue, skey
End If
Next y
End Function
答案 0 :(得分:0)
正如Mat的Mug所说,确保将集合设置为对象引用。一种方法是将set collect = new collection
放在for循环之前。