需要与数组的每个循环索引
我有一个数组,我从Excel表中填充Varibles。 然后我使用每个循环来循环这个数组。 数组的排列与我想填充的某个单元格分配。
'arRow is a Dynamic Array, that varies in size For each vIndex in arRow if vIndex = 0 then 'do nothing else 'Populate corisponding cell Cells(2, ???).value = vIndex end if next vindex
我如何find每个循环的索引?
你可以通过两种方法来完成。 这两种方法都需要一个“计数器”的sorting,因为该数组没有任何可以访问的索引属性。
有了柜台:
Dim i as Long i = 0 For each vIndex in arRow i = i + 1 if vIndex = 0 then 'do nothing else 'Populate corisponding cell Cells(2, i).value = vIndex end if next vindex
或者在数组上使用索引循环(假定是一维数组,但可以根据需要修改为多维):
Dim i For i = LBound(arRow) to UBound(arRow) ... Next
这填充B1:B3
arRow = Array(11, 22, 33) For vIndex = 0 To UBound(arRow) Cells(vIndex + 1, 2).Value = arRow(vIndex) Next