Solved

VBA: Range inside a Range

Posted on 2004-03-30
7
553 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
[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
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

724 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