Enumerating a multi-dimensional array
Rather than looping, consider
Sheets("Contents").Range("F3").Resize(UBound(locat ionNames,1),_
UBound(locationNames,2)).Value = locationNames
Alan Beban
Robert Stober wrote:
Alan,
Thank you. I also figured it out. Here's what I came up with (sorry about
the double spaces):
Dim j As Integer
Dim k As Integer
For j = LBound(locationNames, 1) To UBound(locationNames, 1)
For k = LBound(locationNames, 2) To UBound(locationNames, 2)
Sheets("Contents").Range("F3").Cells(j, k).Value = locationNames(j,
k)
Next k
Next j
Thank you for answering my question.
Robert
"Alan Beban" wrote in message
...
Well, sorta'. You say it's multi-dimensional and not one-dimensional; is
it two-dimensional? Three-dimensional? Is it a secret?
If it's two-dimensional,
For i = LBound(fruits,1) to UBound(fruits,1)
For j=LBound(fruits,2) to UBound(fruits,2)
Debug.Print i,j,fruits(i,j)
Next j
Next i
If it's three-dimensional,
For i = LBound(fruits,1) to UBound(fruits,1)
For j=LBound(fruits,2) to UBound(fruits,2)
For k=LBound(fruits,3) to UBound(fruits,3)
Debug.Print i,j,k,fruits(i,j,k)
Next k
Next j
Next i
etc.
Alan Beban
Robert Stober wrote:
Alan,
I want to print out every defined value in the array. For instance if
this
were a standard (one-deminsional) array, I could write:
Sub PrintArray()
Dim fruits As Variant
Dim i As Integer
fruits = Array("grapes", "pineapples", "kiwi")
For i = LBound(fruits) To UBound(fruits)
Debug.Print fruits(i)
Next i
End Sub
But my array isn't one deminsional, and I don't quite understand how my
data
is being put into the array. There's a second argument to LBound and
UBound
that I don't quite understand yet, so I want to print the contents of my
array so I can see how my data is organized.
Does that clear it up?
Thank you,
Robert
"Alan Beban" wrote in message
...
Perhaps you could clarify what "enumerate the whole thing" means?
Alan Beban
Robert Stober wrote:
Hi,
I've built a multi-dimensional array from a table and would like to
enumerate the whole thing, but I'm confused. Can anyone help me out?
Thank you,
Robert Stober
|