[VBA] Setting 2nd dimention of a 2D-array

faarikaal

New Member
Joined
Aug 10, 2009
Messages
9
Hi there

Im trying for quite some time now to set the array in the 2nd dimention of a 2D-array to the result of a function which returns an array of dbl but i just can't get it to work.

The result of the Interpolate-function has the same length as mintSpan.

Any suggestions or comments are welcome... Thanks in advance

Code:
ReDim dblProductionRate(1 To 5, 1 To mintSpan)
 
For intHC = 1 To 5
        If CheckHC(intHC) And Owner.CheckHC(intHC) Then
            dblProductionRate(intHC) = InterpolateProductionProfile(intHC, mdblReserves(intHC), GetProfiles(intHC))
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,
You have declared dblProductionRate as a 2D array, therefore to assign anything to an element of the array, you have to specify both dimensions. Alternatively, depending on your circumstances, it may be that you actually wanted a 1D array of arrays?
 
Upvote 0
How would I then go about doing that? My head is so focused on 2D arrays im blind towards any other solution.

Im trying to use as little memory as possible and would like not to use variants.
 
Upvote 0
You would declare the variable as an array of arrays using:
Code:
Dim dblProductionRate(1 To 5) As Double()
then you would return your array as you are now.
 
Upvote 0
Sorry, I'm having a day of madness. You would declare it as Variant.
 
Upvote 0
Dim dblProductionRate(1 To 5) As Variant() still gives my compile error.

BTW; thanks for quick replies. Im holding up a group of less then motvated Not-VBA-developers here :)
 
Upvote 0
It's just:
Code:
Dim dblProductionRate(1 To 5) As Variant
 
Upvote 0
Sorry; Im getting a bit confused here.

Is the variant then an array? How do i then reference i.e. the 10th element inside the Variant. Can you reference it like a Collection/Array?

I.e dblProductionRate(1)(10)?
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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