Add Entire Row to Existing Multi-Dimensional Array

mugginsjr

New Member
Joined
Nov 29, 2011
Messages
40
I have a single array of row numbers. I need to create another array, this one multidimensional, to hold all 12 columns of data from just those rows in the first array. The needed rows are not contiguous. I want to avoid the time consuming loops if possible. I'd like to add each entire row on the sheet into each row of the array if possible. This is kind of what I have in mind:

Code:
'  Ubound(row_Pointer_Array) = 39427

Redim new_Array( 1 to Ubound(row_Pointer_Array), 1 to 12)
For i = 1 to  Ubound(row_Pointer_Array)
          new_Array(i) = Range("A" &  row_Pointer_Array(i) & ":P" &  row_Pointer_Array(i))
Next i
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Firstly I'd like to point out that A to P is not only 12 columns :)

Something like this is required:

Code:
Dim i As Long
Dim j As Long

' UBound(row_Pointer_Array) = 39427

ReDim new_array(1 To UBound(row_Pointer_Array), 1 To 12)
For i = 1 To UBound(row_Pointer_Array)
    For j = 1 To 12
        new_array(i, j) = Cells(row_Pointer_Array(i), j).Value
    Next j
Next i

WBD
 
Upvote 0
Thanks... I was afraid that a loop might be necessary. All in all, though, it's not too bad with execution time running less than .4 seconds. The real time problem is going to come later with all the things I need to do with the new array. Every millisecond counts with these large arrays.

Firstly I'd like to point out that A to P is not only 12 columns :)

:) Yeah, hah! I figured that out later when I was coding the loop... 16 columns.

Something like this is required:

Code:
Dim i As Long
Dim j As Long

' UBound(row_Pointer_Array) = 39427

ReDim new_array(1 To UBound(row_Pointer_Array), 1 To 12)
For i = 1 To UBound(row_Pointer_Array)
    For j = 1 To 12
        new_array(i, j) = Cells(row_Pointer_Array(i), j).Value
    Next j
Next i

WBD
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,913
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top