Selecting multiple named ranges

T

Ted M H

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
doesn’t work.
My array is: Dim vSelections(1 to 100) as Variant
I fill the first three elements with the names above. I’ve tried
Range("vSelections(1), vSelections(2),vSelection(3)").Select
and
Range(vSelections(1), vSelections(2) ,vSelection(3)).Select
But these don’t work. I think I’m missing something simple, but I
can’t figure it out. Any suggestions?
 
P

Patrick Molloy

use the UNION method

Option Explicit
Sub demo()
Dim target As Range
Set target = Union(Range("A1:A5"), Range("C5:D10"), Range("B15:F15"))
target.Select
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