如何为数组创建动态变量名称?

时间:2015-07-25 22:31:21

标签: arrays vba excel-vba combobox excel

我有" ComboBox1"包含条目。每次用户选择条目时,都会触发以下内容:

Private Sub ComboBox1_Change()
    call populate(ComboBox1.ListIndex)
End Sub

功能"填充"有以下内容:

Sub populate(index as integer)

    dim arr0, arr1, arr2 ...
        arr0 = Array(...)
        arr1 = Array(...)
        arr2 = Array(...)

    Do While x < Application.CountA("arr" + index)
        ...
    Loop

End Sub

我想要&#34; arr&#34; + index 动态,因此它根据从调用函数接收的索引调用正确的数组。可以这样做吗?

1 个答案:

答案 0 :(得分:2)

Sub populate(index as integer)

    dim arr(0 to 2)
        arr(0) = Array(...)
        arr(1) = Array(...)
        arr(2) = Array(...)

    Do While x < Application.CountA(arr(index))
        ...
    Loop

End Sub