Solved

CELL INTERSECT

Posted on 2014-04-06
5
200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

863 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

19 Experts available now in Live!

Get 1:1 Help Now