-- Sample Data---
[TABLE="width: 256"]
<colgroup><col width="64" span="4" style="width: 48pt; text-align: center;"> </colgroup><tbody>[TR]
[TD="width: 64, align: center"][TABLE="width: 256"]
<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Grandparent[/TD]
[TD="width: 64"]Parent[/TD]
[TD="width: 64"]Child[/TD]
[TD="width: 64"]Fee[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ON[/TD]
[TD]A[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]ON[/TD]
[TD]B[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]ON[/TD]
[TD]C[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UP[/TD]
[TD]D[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]UP[/TD]
[TD]E[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]UP[/TD]
[TD]F[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]XL[/TD]
[TD]G[/TD]
[TD]35[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]XL[/TD]
[TD]H[/TD]
[TD]40[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]XL[/TD]
[TD]I[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]FT[/TD]
[TD]J[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]FT[/TD]
[TD]K[/TD]
[TD]55[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]FT[/TD]
[TD]L[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ON[/TD]
[TD]M[/TD]
[TD]65[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]ON[/TD]
[TD]N[/TD]
[TD]70[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]ON[/TD]
[TD]O[/TD]
[TD]75[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]WP[/TD]
[TD]P[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]WP[/TD]
[TD]Q[/TD]
[TD]85[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]WP[/TD]
[TD]R[/TD]
[TD]90[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]BK[/TD]
[TD]S[/TD]
[TD]95[/TD]
[/TR]
[TR]
[TD="class: xl65"]3[/TD]
[TD="class: xl65"]BK[/TD]
[TD]T[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD="class: xl65"]3[/TD]
[TD="class: xl65"]BK[/TD]
[TD]U[/TD]
[TD]105[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]ON[/TD]
[TD]V[/TD]
[TD]110[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64, align: center"][/TD]
[TD="class: xl65, width: 64, align: center"][/TD]
[TD="width: 64, align: center"][/TD]
[/TR]
</tbody>[/TABLE]
The data above shows a family tree. I want to store this data in a suitable data structure "Multidimensional array" and use indexes to access the Fee.
The indexes are generated from user form controls in a different sheet. I want to be able to pass the indexes as arguments to a function and retrieve the fee of a particular child depending on his ancestors i.e grandparent & parent.
How can I store this data into a multidimensional array and access the product price by passing the indexes as arguments to a function?
I have a function that works well for a perfect 3*3 matrix "with the indexes are passed in as arguments" I want to be able to use it even when the child count for the ancestors is not a perfect 3
[TABLE="width: 256"]
<colgroup><col width="64" span="4" style="width: 48pt; text-align: center;"> </colgroup><tbody>[TR]
[TD="width: 64, align: center"][TABLE="width: 256"]
<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Grandparent[/TD]
[TD="width: 64"]Parent[/TD]
[TD="width: 64"]Child[/TD]
[TD="width: 64"]Fee[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ON[/TD]
[TD]A[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]ON[/TD]
[TD]B[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]ON[/TD]
[TD]C[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UP[/TD]
[TD]D[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]UP[/TD]
[TD]E[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]UP[/TD]
[TD]F[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]XL[/TD]
[TD]G[/TD]
[TD]35[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]XL[/TD]
[TD]H[/TD]
[TD]40[/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]XL[/TD]
[TD]I[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]FT[/TD]
[TD]J[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]FT[/TD]
[TD]K[/TD]
[TD]55[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]FT[/TD]
[TD]L[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ON[/TD]
[TD]M[/TD]
[TD]65[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]ON[/TD]
[TD]N[/TD]
[TD]70[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]ON[/TD]
[TD]O[/TD]
[TD]75[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]WP[/TD]
[TD]P[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]WP[/TD]
[TD]Q[/TD]
[TD]85[/TD]
[/TR]
[TR]
[TD="class: xl65"]2[/TD]
[TD="class: xl65"]WP[/TD]
[TD]R[/TD]
[TD]90[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]BK[/TD]
[TD]S[/TD]
[TD]95[/TD]
[/TR]
[TR]
[TD="class: xl65"]3[/TD]
[TD="class: xl65"]BK[/TD]
[TD]T[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD="class: xl65"]3[/TD]
[TD="class: xl65"]BK[/TD]
[TD]U[/TD]
[TD]105[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]ON[/TD]
[TD]V[/TD]
[TD]110[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64, align: center"][/TD]
[TD="class: xl65, width: 64, align: center"][/TD]
[TD="width: 64, align: center"][/TD]
[/TR]
</tbody>[/TABLE]
The data above shows a family tree. I want to store this data in a suitable data structure "Multidimensional array" and use indexes to access the Fee.
The indexes are generated from user form controls in a different sheet. I want to be able to pass the indexes as arguments to a function and retrieve the fee of a particular child depending on his ancestors i.e grandparent & parent.
How can I store this data into a multidimensional array and access the product price by passing the indexes as arguments to a function?
I have a function that works well for a perfect 3*3 matrix "with the indexes are passed in as arguments" I want to be able to use it even when the child count for the ancestors is not a perfect 3
Code:
Function itemprice(a, e, c, d, Optional ByVal z As Integer = 0)
Dim Items(1 To 3, 1 To 3, 1 To 3) As String
Dim Itemz(1 To 3, 1 To 3, 1 To 3) As String
Dim b As Integer, s As Integer, i As Integer, h As Integer
h = 2
For b = 1 To 3
For s = 1 To 3
For i = 1 To 3
Items(b, s, i) = Worksheets("index").Cells(h, 8).Offset(0, d).Value
Itemz(b, s, i) = Worksheets("index").Cells(h, 8).Offset(0, d).Value + _
Worksheets("index").Cells(h, 8).Offset(0, 1).Value
'If Items(b, s, i) = "D" Then itemprice = b & s & i
h = h + 1
Next i
Next s
Next b
If z Then itemprice = Itemz(a, e, c) Else itemprice = Items(a, e, c)
End Function
Last edited by a moderator: