Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CELL INTERSECT

Posted on 2014-04-06
5
Medium Priority
?
208 Views
Last Modified: 2014-04-11
I have an array of name ranges
KEEPOUT_RAN_GES = Split(",FORMTITLE,FORM_TITLE_OFFSET,DATE_CAPTION", Chr(44))
i would like to know if the activecell falls with in the any of the name range and if it does get the location.can this be done without looping
0
Comment
Question by:Svgmassive
[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
5 Comments
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 2000 total points
ID: 39982081
I don't think the solution is pretty, but this avoids any looping:
Set rngIn = Intersect(activecell, union(activesheet.range("FORMTITLE"), activesheet.range("FORM_TITLE_OFFSET"), activesheet.range("DATE_CAPTION")))
If rngIn Is Nothing Then
   Debug.Print "Not In Range"
Else
   Debug.Print "In Range"
End If

Open in new window


This can also be written as
If Intersect(activecell, union(activesheet.range("FORMTITLE"), activesheet.range("FORM_TITLE_OFFSET"), activesheet.range("DATE_CAPTION"))) Is Nothing Then
   Debug.Print "Not In Range"
Else
   Debug.Print "In Range"
End If

Open in new window

0
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 39982083
You could create a single named range = union() of the named ranges and then only test that intersection.  If you do this a lot in your code, it might be quicker as well as easier to read.
0
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 2000 total points
ID: 39982090
It also looks like this form will work, eliminating the need for the Union() function.
If Intersect(activecell, activesheet.range("FORMTITLE,FORM_TITLE_OFFSET,DATE_CAPTION")) Is Nothing Then
   Debug.Print "Not In Range"
Else
   Debug.Print "In Range"
End If

Open in new window

0
 

Author Comment

by:Svgmassive
ID: 39986558
if i create a union of the ranges is it possible to determine what name range the cell intersects?
0
 
LVL 46

Expert Comment

by:aikimark
ID: 39986595
No.  Your question was determination of whether the activecell was in several named rages or not.  The location using Intersect() will always be the activecell.  If you need to narrow down the result so that you know WHICH named region accounts for the intersection, then you must iterate them.

For that, you should probably create a function that will return the name of the range (or the actual range object) in which the active cell resides.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

715 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