Solved

Excel VBA: Nested Areas in a Range object ?

Posted on 2016-07-20
6
145 Views
Last Modified: 2016-07-21
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 ?
0
Comment
Question by:AL_XResearch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Jeff Darling
ID: 41721657
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
Next

For Each itm In Area2Rng
  lstRangesArea2.AddItem itm.Address
Next

For Each itm In Area3Rng
  lstRangesArea3.AddItem itm.Address
Next

For Each itm In Area4Rng
  lstRangesArea4.AddItem itm.Address
Next

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

For Each itm In unionRng
  lstRangesUnion.AddItem itm.Address
Next

Open in new window


I predefined the ranges.

predefined ranges.
0
 
LVL 3

Author Comment

by:AL_XResearch
ID: 41721693
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 ?
0
 
LVL 13

Assisted Solution

by:Jeff Darling
Jeff Darling earned 250 total points
ID: 41721820
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
  Next
Next

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.
0
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
LVL 3

Author Comment

by:AL_XResearch
ID: 41721987
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.
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 41722189
Hi,

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) .

Regards
0
 
LVL 3

Author Comment

by:AL_XResearch
ID: 41722284
Rgonzo1971: That was the conformation I was looking for.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question