redim preserve matrix doesnt work (the preserve part)

Pascalvrolijk

Board Regular
Joined
May 28, 2004
Messages
68
Hi dearest helping hand,

Been trying but cant find out the solution..
I have a dynamic matrix that gets an extra row within a forloop (time and time again until there are between 3,000,000 and 4,000,000 rows). I want to keep the previous lines as well but redim preserve doesnt work for reason i dont understand. Could someone please help me? The matrix is defined as Variant.

part of the code within a loop is:

k = k + 1
ReDim VBA_matrix(1 To k, 1 To 5)


in second line it gives error 9 during running, subscribt falls out of reach.

Thanks for any and all help!

Greetings,
Pascal.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
you are missing the Preserve keyword
 
Upvote 0
thx diddi, sorry i didnt write the preserve keyword because i set it back to a working version. Its the following code that doesnt work:

k = k + 1
Redim Preserve VBA_matrix((1 To k, 1 To 5)
 
Upvote 0
Your array should be like this:-
Code:
Redim Preserve VBA_matrix((1 To 5, 1 To k)
You can only "Redim" the last dimension on multi dimensional arrays!!!
 
Upvote 0
There is a limit on the Transpose Function that may preclude you from using it with all those rows.
Normally you would build the array on its side and then transpose when placing Back to a sheet.
 
Upvote 0
ok i was exactly afraid for that. Do you think i could use the following (thinking of the big size and that i want to use Correl function on rows and not on columns)?:
correlationmatrix(i, j) = Application.WorksheetFunction.Correl(Application.Index(VBA_matrix, 0, i), Application.Index(VBA_matrix, 0, j))

Thanks in advance, been a great help already!
Greetings,
Pascal.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,055
Latest member
excelhelp12345

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