vba循环遍历基于已定义数组(6,12)的多维数组,用于数组(0,x)

时间:2018-03-27 21:48:49

标签: vba access

我需要使用(0,x){x = 0-11 values}中的值循环遍历数组。我应该如上所述使用循环但是嵌套在一个值递增循环中吗?

DIM H as Integer
DIM vItem As Variant
DIM AssociateArray(6,12)    
...
data is populated into AssociateArray
...    
For Each vItem in AssociateArray
   debug.print vItem
   Select Case vItem
     Case "AAA"
       do this
     Case "BBB"
       do this
  End Select
Next

1 个答案:

答案 0 :(得分:1)

你实际上只是想用(0,x)?

遍历每列的相同行号

以下是一个如何工作但使用(1,x)作为从工作表读入的数据创建基于1的数组而不是零的示例。显示逻辑。

如果你需要在11点结束,你可以循环到UBound(AssociateArray,2) -1

Sub test()

    Dim AssociateArray() ''Dim AssociateArray(6, 12)

    AssociateArray = ThisWorkbook.Worksheets("Sheet3").Range("A1").CurrentRegion.Value

    '(1 to 6, 1 to 12). Reading from sheet creates 1 based array not 0. Imagine actually 0 would replace 0 with 1 below

    ' (0,x)  would be (1,x)

    Dim x As Long

    For x = LBound(AssociateArray, 2) To UBound(AssociateArray, 2)

        Debug.Print AssociateArray(1, x)

    Next x

End Sub

表格中的数据:

Data