Excel VBA: Nested Areas in a Range object ?

AL_XResearch used Ask the Experts™
I am fairly sure this is not possible but I wanted to 'bounce it off' my fellow Excel experts to be sure.

When you have a range object that includes multiple non-contiguous ranges they are represented as child 'Area' objects of a master Range object. If you have multiple ranges which each contain multiple areas and you combine those ranges will you only get one 'level' or area objects or can each area object include multiple areas in a nested fashion ?

It appears to me, and common sense. that when a new range is created out of a union of combined ranges their multi-area reference notation is simply combined together so it appears as if you had selected all the areas in one range object. In which case it is not possible that one of more areas in a range will itself contain multiple areas.

Am I right ?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jeff DarlingDeveloper Analyst

I think one way to test this is to look at some VBA with a union of some ranges that overlap.

Excel Range Union Test
Dim Area1Rng As Range
Dim Area2Rng As Range
Dim Area3Rng As Range
Dim Area4Rng As Range

Set Area1Rng = Range("Area1")
Set Area2Rng = Range("Area2")
Set Area3Rng = Range("Area3")
Set Area4Rng = Range("Area4")

For Each itm In Area1Rng
  lstRangesArea1.AddItem itm.Address

For Each itm In Area2Rng
  lstRangesArea2.AddItem itm.Address

For Each itm In Area3Rng
  lstRangesArea3.AddItem itm.Address

For Each itm In Area4Rng
  lstRangesArea4.AddItem itm.Address

Dim unionRng As Range
Set unionRng = Union(Area1Rng, Area2Rng, Area3Rng, Area4Rng)

For Each itm In unionRng
  lstRangesUnion.AddItem itm.Address

Open in new window

I predefined the ranges.

predefined ranges.


So you're agreeing with me ?

To put another way; is there any way to create a range object where the areas within it themselves have areas ?
Jeff DarlingDeveloper Analyst
I'm trying to understand what the question is.

Maybe an array of ranges like this?

Dim prog2Rng(3) As Range
Set prog2Rng(0) = Range("Area1")
Set prog2Rng(1) = Range("Area2")
Set prog2Rng(2) = Range("Area3")

Dim i

For i = 0 To UBound(prog2Rng) - 1
  For Each itm In prog2Rng(i)
   lstRangesTest.AddItem itm.Address

Open in new window

Then if you process each range in the array, that will give you what you want?  

another screenshot.
notice that the duplicates are not removed when done this way.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.


That doesn't really answer my question i am afraid.

What I am trying to determine is: Is it possible for the area object of a range to itself contain areas ?

I don't think so but I am looking for other's opinions.
Top Expert 2016

When you create a new range by Union of many Ranges, the new range has its own areas, it does not have the memory of past areas( or sub-areas) .



Rgonzo1971: That was the conformation I was looking for.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial