extending array per every input

Lavina

Board Regular
Joined
Dec 18, 2018
Messages
75
Hey guys,

im trying to fill up my array and extended whenever needed:

Code:
arraySizeX = 1
arraySizeY = 2
ReDim Preserve orderArray(1 To arraySizeX, 1 To arraySizeY)
orderArray(1, 1) = "test"
orderArray(1, 2) = lastRow - 1
arraySizeX = arraySizeX + 1
ReDim Preserve orderArray(1 To arraySizeX, 1 To arraySizeY)
orderArray(2, 1) = "test2"
orderArray(2, 2) = Range("M2:M" & lastRow).Count

And i hit the error: subscript out of range, why is it happening?
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Take a look at
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/redim-statement

You find...
"[FONT=&quot]If you use the [/FONT]Preserve[FONT=&quot] keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array."

M.
[/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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