Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Get Name of Selected Range

Good Morning,

Is there a method or property that returns the Name (if any) of a selected
or specific range? Something like:

NameOfRange = ThisWorkbook.Names.Item(Selection).Name
NameOfRange = ThisWorkbook.Names.Item(ActiveCell).Name
NameOfRange = ThisWorkbook.Names.Item(Cells(1, 1)).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1")).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1:B2")).Name

TIA
Charlie

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Get Name of Selected Range

Charlie,

No. You need to iterate through the names collection:

Dim myname As Name
For Each myname In ActiveWorkbook.Names
If Selection.Address = Range(myname).Address Then
MsgBox "The selection is named " & myname.Name
End If
Next

HTH,
Bernie
MS Excel MVP


"Charlie" wrote in message
...
Good Morning,

Is there a method or property that returns the Name (if any) of a selected
or specific range? Something like:

NameOfRange = ThisWorkbook.Names.Item(Selection).Name
NameOfRange = ThisWorkbook.Names.Item(ActiveCell).Name
NameOfRange = ThisWorkbook.Names.Item(Cells(1, 1)).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1")).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1:B2")).Name

TIA
Charlie



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Get Name of Selected Range

Thanks, that was what I figured.

"Bernie Deitrick" wrote:

Charlie,

No. You need to iterate through the names collection:

Dim myname As Name
For Each myname In ActiveWorkbook.Names
If Selection.Address = Range(myname).Address Then
MsgBox "The selection is named " & myname.Name
End If
Next

HTH,
Bernie
MS Excel MVP


"Charlie" wrote in message
...
Good Morning,

Is there a method or property that returns the Name (if any) of a selected
or specific range? Something like:

NameOfRange = ThisWorkbook.Names.Item(Selection).Name
NameOfRange = ThisWorkbook.Names.Item(ActiveCell).Name
NameOfRange = ThisWorkbook.Names.Item(Cells(1, 1)).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1")).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1:B2")).Name

TIA
Charlie




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Get Name of Selected Range

try

Sub GetName()
'Leo Heuser April 8, 2005
Dim Nam As Name


For Each Nam In ActiveWorkbook.Names
If Not Intersect(ActiveCell, Range(Nam.RefersTo)) Is Nothing Then
MsgBox Nam.Name
End If
Next Nam


End Sub



--
Don Guillett
SalesAid Software

"Charlie" wrote in message
...
Good Morning,

Is there a method or property that returns the Name (if any) of a selected
or specific range? Something like:

NameOfRange = ThisWorkbook.Names.Item(Selection).Name
NameOfRange = ThisWorkbook.Names.Item(ActiveCell).Name
NameOfRange = ThisWorkbook.Names.Item(Cells(1, 1)).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1")).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1:B2")).Name

TIA
Charlie



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Get Name of Selected Range

Charlie,

I got sloppy, and forgot about needing to check the named range's parent sheet.

You should use something like this one:

Sub TryNow()
Dim myname As Name
For Each myname In ActiveWorkbook.Names
If Selection.Address(, , , True) = Range(myname).Address(, , , True) Then
MsgBox "The selection is named " & myname.Name
Exit Sub
End If
Next
MsgBox "The selection is not a named range"
End Sub

HTH,
Bernie
MS Excel MVP


"Charlie" wrote in message
...
Thanks, that was what I figured.

"Bernie Deitrick" wrote:

Charlie,

No. You need to iterate through the names collection:

Dim myname As Name
For Each myname In ActiveWorkbook.Names
If Selection.Address = Range(myname).Address Then
MsgBox "The selection is named " & myname.Name
End If
Next

HTH,
Bernie
MS Excel MVP


"Charlie" wrote in message
...
Good Morning,

Is there a method or property that returns the Name (if any) of a selected
or specific range? Something like:

NameOfRange = ThisWorkbook.Names.Item(Selection).Name
NameOfRange = ThisWorkbook.Names.Item(ActiveCell).Name
NameOfRange = ThisWorkbook.Names.Item(Cells(1, 1)).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1")).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1:B2")).Name

TIA
Charlie








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Get Name of Selected Range

Charlie wrote:
Good Morning,

Is there a method or property that returns the Name (if any) of a selected
or specific range? Something like:

NameOfRange = ThisWorkbook.Names.Item(Selection).Name
NameOfRange = ThisWorkbook.Names.Item(ActiveCell).Name
NameOfRange = ThisWorkbook.Names.Item(Cells(1, 1)).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1")).Name
NameOfRange = ThisWorkbook.Names.Item(Range("A1:B2")).Name

TIA
Charlie

E.g.:

Sub testIt3a()
On Error Resume Next
MsgBox Selection.Name.Name
If Err < 0 Then MsgBox "The specified range is not a named range"
End Sub

Alan Beban
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
how to add 130% to a selected range of numbers ? MATHIMATICALLY IMPAIRED Excel Discussion (Misc queries) 4 January 14th 09 05:22 PM
Appearance of a selected range d_mack Excel Discussion (Misc queries) 10 October 5th 07 12:31 AM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
How can I set a range can't be selected! cherishman Excel Programming 2 May 28th 05 01:42 PM
Box around selected range Tom Ogilvy Excel Programming 1 September 7th 03 04:42 PM


All times are GMT +1. The time now is 11:01 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"