I have a dynamic 2 dimensional array that has way more data than i need and i only want to write certain elements (columns) of the array back to the worksheet. Is this possible? For example:
Sub writeArray()
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim arSource() As Variant
Dim a As Long
Dim b As Long
Set wsDest = wbPT.Worksheets("Import")
Set wsSource = wbSource.Worksheets("Export")
wsDest.Activate
ReDim Preserve arSource(3 To wsSource.Range("B" & Rows.Count).End(xlUp).row, 2 To 40) '
For a = LBound(arSource, 1) To UBound(arSource, 1)
For b = LBound(arSource, 2) To UBound(arSource, 2)
arSource(a, b) = wsSource.Cells(a, b)
Next b
Next a
End Sub
This array has 3 to 271 elements in the first dimension and 2 to 40 in the second dimension.
Of the 39 elements (columns) I only want these columns: 4, 5, 6, 7, 8, 23, 35, and 36.
On the destination worksheet that correlates to columns: 2, 3, 4, 5, 6, 7, 13, and 14. I would need column 4 from the source array to now move to column 2 on the destination worksheet and column 5 from the source to be in column 3 in the destination sheet and so on with the 8 columns. I do not need any of the other data. - Should I be trying to do this another way?