There *is* a limitation on the lines of code I suggested below, at least
in xl versions up through xl2000 (and perhaps later as well, I don't
know), though it's not a limitation on the aresize code. I don't know
if it's relevant because I don't know how large your data will get to
be, but the Index function as used below will fail if the number of
elements of Array1 in the first two dimensions exceeds 5461.
This limitation can be avoided if the functions in the freely
downloadable file at
http://home.pacbell.net/beban are available to your
workbook, a la
...
If the goal is iterating over the subarray for which the 3rd of 5 dimensions
equals 9, using aresize to coerce to 2D followed by ColumnVector followed by
another aresize call to restore 5D is grossly wasteful of system resources. It'd
be simpler to use something like the following to find the max value in all
entries in the subarray Array1(.,.,9,.,.).
Dim d(1 To 6) As Long, i As Long, x As Variant, maxval As Variant
'one more dimension in d than in Array1
d(1) = 1
For i = 2 To 6
d(i) = d(i - 1) * UBound(Array1, i - 1) 'assuming Array1 is 1-based
Next i
i = 0
For Each x In Array1
i = i + 1
If Int(1 + ((i - 1) Mod d(4)) / d(3)) = 9 Then
If IsEmpty(maxval) Or x > maxval Then maxval = x
End If
Next x
This could be the core of a general purpose array slicing function, but I'm too
lazy right now to implement it. To create a subarray aa for which the 3rd of 5
dimensions is 9, define aa using
ReDim aa(1 To UBound(Array1, 1), 1 To UBound(Array1, 2), _
1 To UBound(Array1, 4), 1 To UBound(Array1, 5))
and replace the 'If IsEmpty...' statement in the code above with
aa(Int(1 + ((i - 1) Mod d(2)) / d(1)), Int(1 + ((i - 1) Mod d(3)) / d(2)), _
Int(1 + ((i - 1) Mod d(5)) / d(4)), Int(1 + ((i - 1) Mod d(6)) / d(5))) = x
While d(1) and d(6) are technically unnecessary, they simplify iterative
techniques for generating the indices of aa as you iterate through Array1 using
For Each.