MultiDimensional Array Output

D

Dnk

The following code fills an array with values from 1 to 25.
Sub FillArray()
Dim f As Integer
Dim s As Integer
Dim t As Integer
Dim c As Integer
Dim m As Integer
Dim myArray(1 To 10, 1 To 10, 1 To 10)
c = 1
For f = 1 To 10
For s = 1 To 10
For t = 1 To 10
myArray(f, s, t) = n
c = c + 1
n = n + 1
If n = 26 Then n = 1
Debug.Print myArray(f, s, t), c

Next t
Next s
Next f
End Sub


The array contains 1000 elements which can be visualized as 10 rows x
10 colunms x 10 deep.

Is it possible to look at the array in the form of a cube and take 10
matrices from the front to back, 10 matrices from the right to the
left and 10 matrices from the top to the bottom. and output to a
worksheet with a row between each matrix?

This would be 30, 10 X 10 matrices.

Thanks
 
T

Tom Ogilvy

Not as a single step. See if this does what you want:

Sub FillArray()
Dim f As Integer
Dim s As Integer
Dim t As Integer
Dim c As Integer
Dim m As Integer
Dim myArray(1 To 10, 1 To 10, 1 To 10)
c = 1
For f = 1 To 10
For s = 1 To 10
For t = 1 To 10
myArray(f, s, t) = "A" & f & ", B" & s & ", C" & t
' c = c + 1
' n = n + 1
' If n = 26 Then n = 1
' Debug.Print myArray(f, s, t), c

Next t
Next s
Next f

Dim dum(1 To 10, 1 To 10)
Dim rng As Range

For e = 1 To 3
If e = 1 Then
Range("A1").Value = "1 Dimension"
Else
Set rng = Cells(Rows.Count, 1).End(xlUp)(3)
rng.Value = e & " Dimension"
End If
For j = 1 To 10
Erase dum
For f = 1 To 10
For s = 1 To 10
For t = 1 To 10
Select Case e
Case 1
If f = j Then
dum(s, t) = myArray(f, s, t)
End If
Case 2
If s = j Then
dum(t, f) = myArray(f, s, t)
End If
Case 3
If t = j Then
dum(f, s) = myArray(f, s, t)
End If
End Select
Next t
Next s
Next f
If i = 1 And f = 1 Then
Set rng = Range("A3")
Else
Set rng = Cells(Rows.Count, 1).End(xlUp)(3)
End If
rng.Resize(10, 10) = dum
Next j
Next e

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top