Create array of varying length?

mae0429

Board Regular
Joined
Jun 12, 2008
Messages
114
I have a bit of a conundrum here: I am going to have sets of data that will have different numbers of rows, and I store the last used row as "LastRow". I am writing a function that will enter the values of certain columns into an array.

Is it possible to pass the "LastRow" variable to a function as a Variant, and then create an array in a way such as this:
Dim myVar(3 To LastRow, 7 To 12) As Double

I know that the array must be of a constant value, but is there a way around this?

Thanks,
-Matt
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi

FYI you can skip the Dim statement altogether and just go with the Redim when you want to declare the array in code:

Code:
Dim LastRow As Long
LastRow = 100
'...

ReDim dVar(3 To LastRow, 7 To 12) As Double</pre>
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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