Using an Array to re-use code

G

godiva

Hi.
I have a series of 37 arrays, each populated with a varying number of
elements, all number (ary_Numbers). I have an additional array
populated with 37 strings ( ary_Arrays).
The goal is to move through ary_Arrays, using the value of ary_Arrays
as the name of ary_Numbers in the subsequent For Each...Next loop.
attempted but failed with type mismatch error:
For Each ary_Name In ary_Arrays
ary2Run = ary_Arrays(ary_name)
'ary_Name would be QW1, ary_Array(1) for example and also
the name of another array
For Each qstNum in ary2Run
'do something here
Next

Next
Is this even possible without getting a type mismatch error? Do I need
to consider putting the array names in a table and looping through the
records to pass the array names to the for each...next loop?
thnx in advance
 
G

George Nicholson

I don't think I've never tried using a for...each loop on an array. Since an
array is not a collection object, I'm not sure it would work. Even if it
did, I'm not sure what it would return: it's numerical position in the array
or it's string value?. If it returned the string value, that might explain a
type mismatch on the second line.

So much for what I don't know. If I was doing it:

For i = lbound(ary_Arrays) to ubound(ary_Arrays)
ary2Run = ary_Arrays(i)
etc...

HTH,
 

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