Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Detect if a selected cell is within a named range

If I have a worksheet with a number of different (non-overlapping)
custom named ares (i.e. part of the WorkSheet.Names collection), is
there any simple way I can detect the region that a selected cell
might be part of?

I could get the row and column index of the cell in question and then
loop through all the Name objects in the collection, testing if it
falls within the R and C range, but I was hoping there might be
something simpler.

Thanks in advance

Craig
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Detect if a selected cell is within a named range

Dim nme As Name

For Each nme In ActiveWorkbook.Names
If Not Intersect(ActiveCell, Range(nme.Name)) Is Nothing Then
MsgBox nme.Name
End If
On Error GoTo 0
Next nme


--

HTH

RP
(remove nothere from the email address if mailing direct)


"CraigB" wrote in message
om...
If I have a worksheet with a number of different (non-overlapping)
custom named ares (i.e. part of the WorkSheet.Names collection), is
there any simple way I can detect the region that a selected cell
might be part of?

I could get the row and column index of the cell in question and then
loop through all the Name objects in the collection, testing if it
falls within the R and C range, but I was hoping there might be
something simpler.

Thanks in advance

Craig



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Detect if a selected cell is within a named range

Note that this will work, but only if

a) all the Names in the workbook refer to ranges, and
b) all the named ranges are on the active sheet.

One workaround:

Dim nmTest As Name
Dim rTest As Range

On Error Resume Next
For Each nmTest In ActiveWorkbook.Names
Set rTest = Intersect(ActiveCell, nmTest.RefersToRange)
If Not rTest Is Nothing Then
MsgBox nmTest.Name
End If
Next nmTest
On Error GoTo 0




In article ,
"Bob Phillips" wrote:

Dim nme As Name

For Each nme In ActiveWorkbook.Names
If Not Intersect(ActiveCell, Range(nme.Name)) Is Nothing Then
MsgBox nme.Name
End If
On Error GoTo 0
Next nme

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
duplicate named ranges- how to detect, delete? Keith R Excel Discussion (Misc queries) 2 June 1st 07 04:41 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
named cell range Marilyn Excel Worksheet Functions 2 March 13th 06 07:42 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM


All times are GMT +1. The time now is 11:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"