[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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Just to clearify (and be annoying) im posting an example to see if it is in accordence with you guys. Thanks a lot gentlemen!

Code:
Function GetArray(ByVal size As Integer) As Double()
 Dim A As Double()
 ReDim A(1 To size)
 ......
 GetArray = A
End Function
.......
Dim A As Double()
ReDim A(1 To 5, 1 To 20)
For i = 1 To 5
 A(i) = GetArray(20)
Next
--------
out = A(i,j)
 
Upvote 0
Nope. Try this:
Code:
Function GetArray(ByVal size As Integer) As Double()
 Dim A As Double()
 ReDim A(1 To size)
 ......
 GetArray = A
End Function
.......
Dim A As Variant
ReDim A(1 To 5)
For i = 1 To 5
 A(i) = GetArray(20)
Next i
--------
out = A(i,j)
 
Upvote 0
More typos:
Code:
Function GetArray(ByVal size As Integer) As Double()
 Dim A() As Double
 ReDim A(1 To size)
 ......
 GetArray = A
End Function
.......
Dim A As Variant
ReDim A(1 To 5)
For i = 1 To 5
 A(i) = GetArray(20)
Next i
--------
out = A(i)(j)
 
Upvote 0
Threw this together so you can try for yourself

Code:
Function GetArray(ByVal size As Integer) As Double()
    Dim I As Integer
    Dim A() As Double
    ReDim A(1 To size)
    For I = 1 To size
        A(I) = I * I
    Next
    GetArray = A
End Function
Sub Main()
    Dim I As Integer
    Dim J As Integer
    Dim A As Variant
    ReDim A(1 To 5)
    For I = 1 To 5
        A(I) = GetArray(20)
        For J = 1 To 20
            Debug.Print A(I, J)
        Next
    Next I
End Sub
 
Upvote 0
Again:
Code:
Debug.Print A(I)(J)
:)
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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