VBA 配列の中に配列を入れてみた

Sub 配列test()
    Dim i As Long, j As Long
    Dim arr1 As Variant
    Dim arr2 As Variant
    Dim arrAll(2) As Variant
    
    arr1 = Range("A1:B10")
    arr2 = Range("D1:E5")   

    arrAll(1) = arr1
    arrAll(2) = arr2   
    
    For i = 1 To UBound(arrAll)
        For j = 1 To UBound(arrAll(i))
            Debug.Print arrAll(i)(j, 1) & "," & arrAll(i)(j, 2)
        Next j
    Next i
End Sub
Sub 配列test()
    Dim i As Long, j As Long, k As Long
    Dim arr1 As Variant
    Dim arr2 As Variant
    Dim arrAll(2) As Variant
    
    ReDim arrAll(2)
    arrAll(1) = (Range("A1:B10"))
    arrAll(2) = (Range("D1:E5"))    

    For i = 1 To UBound(arrAll)
        For j = 1 To UBound(arrAll(i))
            Debug.Print arrAll(i)(j, 1) & "," & arrAll(i)(j, 2)
        Next j
    Next i
End Sub

コメント