Solved

VBA: Range inside a Range

Posted on 2004-03-30
7
540 Views
Last Modified: 2006-11-17
Hi,
i need to find a way to know if a given range is inside other.
In example:
If my range is "F8" and my main target range is "A1:F7", my range is not inside but if my range is "C4" it is.
It would be done without a loop since that would be called several times in a minute and user shoul never know that this function is performed.
If you need more explanation or knows a better approach, i am open to any tip that can solve this matter.
Thanks in advance.
0
Comment
Question by:Richie_Simonetti
  • 4
  • 3
7 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 75 total points
ID: 10714188
Hi,

You need to use "Intersect".

Option Explicit
Public Sub Q_20937308()

  Dim objRange                                          As Range
 
  Set objRange = Intersect(Range("A1:F7"), Range("F8"))
 
  If Not (objRange Is Nothing) Then
     MsgBox "Intersects"
  Else
     MsgBox "Does not Intersect"
  End If
 
  Set objRange = Nothing
 
End Sub


BFN,

fp.

0
 
LVL 16

Author Comment

by:Richie_Simonetti
ID: 10714286
Wow, i never heard that function before!
0
 
LVL 16

Author Comment

by:Richie_Simonetti
ID: 10714308
Many Thanks.
It would be nice if you do a little explanation of how that function works (more than the poor VBA help text ;)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10714413
Well...

Each of the parameters specify ranges in the worksheet and the function (object) is set to the range where all the parameters intersect.

For example,

... = Intersect(Range("A1:Z65535"), Range("B2:G10"), Range("C4:D5"))

will return $C$4:$D$5 as the Address of the Intersect range as this is the range that is present in all three parameter ranges.

Hope that made sense.

Thanks for the points/grading.

BFN,

fp.
0
 
LVL 16

Author Comment

by:Richie_Simonetti
ID: 10714437
many thanks again. I never grade less than an "A", otherwise i directly ask for deletion/PAQ/refund points since if solution works, deserves an "A" otherwise, problem not solved so why to put any grade at all, don't you think so?
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10721439
Hi,

Sometimes links to sites or previous answers with relevance are posted as comments rather than the code or comment relevant to the question, and therefore they may only be worthy of a "B", but yes, I see your point.

HTH.

BFN,

fp.
[http://NigelLee.info]
0
 
LVL 16

Author Comment

by:Richie_Simonetti
ID: 10723931
To me, it doesn't matters if it is genuine code or a link to it.
If it is a solution to the problem, enougth to me.
I posted links several times when answer questions, many times due to links contains code that not belongs to me so, i don't like to 'stole' code from other programmers and pass them as mine.
Cheers
Have a nice day.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

808 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