Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple ranges in an array

Status
Not open for further replies.

Zygor

Technical User
Apr 18, 2001
271
US
Can anyone help me with some syntac in Excel. I am trying to hard code an array with various ranges.

As an example -
Dim varArray As Variant

Set varArray = Array(Range("A1:e5"), Range("G11:G22"))

(This throws a type mismatch error)
 



Hi,

Only OBJECTS get Set
Code:
Dim varArray As Variant

   varArray = Array(Range("A1:e5"), Range("G11:G22"))


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
depending on what you are doing afterwards, you may be better off storing like:

Dim varArray As Variant

varArray = Array("A1:e5", "G11:G22")

You would then reference the range like:

set myRange = Range(varArray(1))





Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 





or...
Code:
set myrange = union(Range("A1:e5"), Range("G11:G22"))


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top