Solved

CELL INTERSECT

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

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 46

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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

627 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