Solved

CELL INTERSECT

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 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