Solved

VBA: Range inside a Range

Posted on 2004-03-30
7
526 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now