【发布时间】:2016-12-07 10:49:44
【问题描述】:
我设法将一系列单元格存储到一个集合中。
我正在尝试使用集合中的每个项目。
我未能通过使用Collection.Item 和debug.Print 在即时窗口中显示它来调用它。
如果我只将一个单元格存储到集合中,这将有效。
lastRowIndex = Cells(Rows.Count, 1).End(xlUp).Row
Set PGname = New Collection
Set HScode = New Collection
For i = 1 To lastRowIndex
PGname.Add Range((Cells(i, 1)), (Cells(i, 2)))
HScode.Add (Cells(i, 2))
Next i
Debug.Print PGname.Item(1) 'this does not work
Debug.Print HScode.Item(1) 'this works
【问题讨论】:
-
为什么你尝试
debug.print一个范围对象通常会发生什么? -
@CallumDA33 这是运行时错误'13':类型不匹配。
标签: vba excel collections