Solved

CELL INTERSECT

Posted on 2014-04-06
5
204 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
  • 4
5 Comments
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 500 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 45

Accepted Solution

by:
aikimark earned 500 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 45

Assisted Solution

by:aikimark
aikimark earned 500 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 45

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

839 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