Late but better than nothing I guess.
Sub Convert2DTo1D() Dim arr2D(1 To 2, 1 To 3) As Variant Dim arr1D() As Variant Dim i As Long, j As Long, k As Long ' Populate the 2D array arr2D(1, 1) = 1 arr2D(1, 2) = 2 arr2D(1, 3) = 3 arr2D(2, 1) = 4 arr2D(2, 2) = 5 arr2D(2, 3) = 6 ' Determine the size of the 1D array ReDim arr1D(1 To UBound(arr2D, 1) * UBound(arr2D, 2)) ' Populate the 1D array k = 1 For i = 1 To UBound(arr2D, 1) For j = 1 To UBound(arr2D, 2) arr1D(k) = arr2D(i, j) k = k + 1 Next j Next i ' Print the 1D array to the Immediate Window For i = 1 To UBound(arr1D) Debug.Print arr1D(i) Next i End Sub




Reply With Quote
