Assigning range names to arrays

K

Kurt Krueger

Hi,

I want to set an array (array_transit) to any one of a number of
ranges in a workbook. I thought that I could store the range names in
an array and then call the array element number in a set range
statement. Didn't work--any suggestions?

Thanks,

Kurt

Function macro_test(parm_range_id_number As Integer) As Variant
Dim array_transit As Range
Dim array_names
array_names(1) = "range_males_all"
array_names(2) = "range_females_all"
.....
array_names(n) = " ... "

array_transit = Range(array_names(parm_range_id_number))

.. . .

End Function
 
D

Dave Peterson

And since array_transit is a range:

set array_transit = range(array_names(parm_range_id_number))

It may work if everything else is ok <vbg>.

Another way of populating that array:

dim parm_range_id_number as long
dim Array_Names as Variant
array_names = array("range_males_all","range_females_all", _
"keepgoing","keepongoing")


for parm_range_id_number = lbound(array_names) to ubound(array_names)
set array_transit = range(array_names(parm_range_id_number))
'do lots of stuff
next parm_range_id_number
 

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