View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default select multiple named ranges with macro


Try the below

Dim varName(1 To 3)
varName(1) = "Name1"
varName(2) = "Name2"
varName(3) = "Name3"
strname = Join(varName, ",")
Range(strname).Select

If this post helps click Yes
---------------
Jacob Skaria


"Ted M H" wrote:

I have a macro that looks at the active cell and determines the named
ranges that it is a part of. It can be one named range or many. I
store the names in an array, one name per element in the array.
After populating the array with the names, I want to select all of the
named ranges that have been stored in the array.
I can do this easily like this:

Range(€œmg_benefits, mg_FY11,mg_fy12€).select

but when I try to do the same thing from my array it
doesnt work.
My array is: Dim vSelections(1 to 100) as Variant

I fill the first three elements with the names above. Ive tried

Range("vSelections(1), vSelections(2),vSelection(3)").Select

and

Range(vSelections(1), vSelections(2) ,vSelection(3)).Select

But these dont work. I think Im missing something simple, but I
cant figure it out. Any suggestions?