vba遍历数组的两种方法
- 这里采用Do While Loop 循环, 重点是得到数组的索引最大值U。用UBound方法。
' 数组循环1
Sub array_loop_demo()
Dim i As Integer, array_n
array_n = Array("A", "B", "C")
i = 0
Do While i <= UBound(array_n)
MsgBox array_n(i)
i = i + 1
Loop
End Sub
- For Each Next 遍历
' 数组循环2
Sub array_loop_demo2()
Dim i, array_n
array_n = Array("A", "B", "C")
For Each i In array_n
MsgBox i
Next i
End Sub
网友评论