Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default Names referring to valid range in the active workbook

hello,

I'm looking for a procedure that identifies Names referring to valid
range in the active workbook (and excludes all names referring to
external workbooks or to formula or to constants....)

Please help
Thanks
Avi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Names referring to valid range in the active workbook

Hi avi.
Try:

Public Sub Macro1()
Selection.ListNames
End Sub

Regards
Eliano


"avi" wrote:

hello,

I'm looking for a procedure that identifies Names referring to valid
range in the active workbook (and excludes all names referring to
external workbooks or to formula or to constants....)

Please help
Thanks
Avi


  #3   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default Names referring to valid range in the active workbook

The procedure returns all the names while i'm interested in only valid
ranges in the active workbook

Thanks
Avi

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Names referring to valid range in the active workbook

avi,

Try this

With ActiveWorkbook
Selection.ListNames
End With

"avi" wrote:

The procedure returns all the names while i'm interested in only valid
ranges in the active workbook

Thanks
Avi


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Names referring to valid range in the active workbook

Sub test2()
Dim cnt As Long
Dim wb As Workbook
Dim nm As Name
Dim rng As Range
Dim arrNames()

Set wb = ActiveWorkbook
cnt = wb.Names.Count

If cnt = 0 Then Exit Sub

ReDim arrNames(1 To cnt, 1 To 2)

cnt = 0

On Error Resume Next
For Each nm In wb.Names
Set rng = Range(nm.Name)
If Not rng Is Nothing Then
If rng.Parent.Parent Is wb Then
cnt = cnt + 1
arrNames(cnt, 1) = nm.Name
arrNames(cnt, 2) = "' " & nm.RefersTo
End If
Set rng = Nothing
Else
Err.Clear
End If
Next

If cnt Then
Range("A1").Resize(cnt, 2).Value = arrNames
End If

End Sub

This will also include formula type names that indirectly refer to a range
in the workbook. It will exclude range names that refer to a range in
another workbook, and other formula or non range names.

Regards,
Peter T

"avi" wrote in message
ups.com...
hello,

I'm looking for a procedure that identifies Names referring to valid
range in the active workbook (and excludes all names referring to
external workbooks or to formula or to constants....)

Please help
Thanks
Avi





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Names referring to valid range in the active workbook

Peter T's code seems to do what you need, but your workbook might
contain named ranges for single worksheets.
So you should add something like

for each ws in wb.worksheets
for each nm in ws.names
....
next nm
next ws

to your code.


Peter T wrote:
Sub test2()
Dim cnt As Long
Dim wb As Workbook
Dim nm As Name
Dim rng As Range
Dim arrNames()

Set wb = ActiveWorkbook
cnt = wb.Names.Count

If cnt = 0 Then Exit Sub

ReDim arrNames(1 To cnt, 1 To 2)

cnt = 0

On Error Resume Next
For Each nm In wb.Names
Set rng = Range(nm.Name)
If Not rng Is Nothing Then
If rng.Parent.Parent Is wb Then
cnt = cnt + 1
arrNames(cnt, 1) = nm.Name
arrNames(cnt, 2) = "' " & nm.RefersTo
End If
Set rng = Nothing
Else
Err.Clear
End If
Next

If cnt Then
Range("A1").Resize(cnt, 2).Value = arrNames
End If

End Sub

This will also include formula type names that indirectly refer to a range
in the workbook. It will exclude range names that refer to a range in
another workbook, and other formula or non range names.

Regards,
Peter T

"avi" wrote in message
ups.com...
hello,

I'm looking for a procedure that identifies Names referring to valid
range in the active workbook (and excludes all names referring to
external workbooks or to formula or to constants....)

Please help
Thanks
Avi



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Names referring to valid range in the active workbook

Worksheet level names also exist in the workbook's Names collection, where
they are listed like this -

SheetName!LocalName

So for the purposes of this exercise it shouldn't be necessary to loop
worksheets and do 'for each nm in ws.names', unless of course the OP
requires that additional local/global info about the name.

Regards,
Peter T


"Luca Brasi" wrote in message
...
Peter T's code seems to do what you need, but your workbook might
contain named ranges for single worksheets.
So you should add something like

for each ws in wb.worksheets
for each nm in ws.names
....
next nm
next ws

to your code.


Peter T wrote:
Sub test2()
Dim cnt As Long
Dim wb As Workbook
Dim nm As Name
Dim rng As Range
Dim arrNames()

Set wb = ActiveWorkbook
cnt = wb.Names.Count

If cnt = 0 Then Exit Sub

ReDim arrNames(1 To cnt, 1 To 2)

cnt = 0

On Error Resume Next
For Each nm In wb.Names
Set rng = Range(nm.Name)
If Not rng Is Nothing Then
If rng.Parent.Parent Is wb Then
cnt = cnt + 1
arrNames(cnt, 1) = nm.Name
arrNames(cnt, 2) = "' " & nm.RefersTo
End If
Set rng = Nothing
Else
Err.Clear
End If
Next

If cnt Then
Range("A1").Resize(cnt, 2).Value = arrNames
End If

End Sub

This will also include formula type names that indirectly refer to a

range
in the workbook. It will exclude range names that refer to a range in
another workbook, and other formula or non range names.

Regards,
Peter T

"avi" wrote in message
ups.com...
hello,

I'm looking for a procedure that identifies Names referring to valid
range in the active workbook (and excludes all names referring to
external workbooks or to formula or to constants....)

Please help
Thanks
Avi





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Names referring to valid range in the active workbook

your right! damn, i coded too much lines for years.... :(

Peter T wrote:
Worksheet level names also exist in the workbook's Names collection, where
they are listed like this -

SheetName!LocalName

So for the purposes of this exercise it shouldn't be necessary to loop
worksheets and do 'for each nm in ws.names', unless of course the OP
requires that additional local/global info about the name.

Regards,
Peter T


"Luca Brasi" wrote in message
...
Peter T's code seems to do what you need, but your workbook might
contain named ranges for single worksheets.
So you should add something like

for each ws in wb.worksheets
for each nm in ws.names
....
next nm
next ws

to your code.


Peter T wrote:
Sub test2()
Dim cnt As Long
Dim wb As Workbook
Dim nm As Name
Dim rng As Range
Dim arrNames()

Set wb = ActiveWorkbook
cnt = wb.Names.Count

If cnt = 0 Then Exit Sub

ReDim arrNames(1 To cnt, 1 To 2)

cnt = 0

On Error Resume Next
For Each nm In wb.Names
Set rng = Range(nm.Name)
If Not rng Is Nothing Then
If rng.Parent.Parent Is wb Then
cnt = cnt + 1
arrNames(cnt, 1) = nm.Name
arrNames(cnt, 2) = "' " & nm.RefersTo
End If
Set rng = Nothing
Else
Err.Clear
End If
Next

If cnt Then
Range("A1").Resize(cnt, 2).Value = arrNames
End If

End Sub

This will also include formula type names that indirectly refer to a

range
in the workbook. It will exclude range names that refer to a range in
another workbook, and other formula or non range names.

Regards,
Peter T

"avi" wrote in message
ups.com...
hello,

I'm looking for a procedure that identifies Names referring to valid
range in the active workbook (and excludes all names referring to
external workbooks or to formula or to constants....)

Please help
Thanks
Avi




  #9   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default Names referring to valid range in the active workbook

Great!

Thaks a lot for your detailed help

Avi

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
Formula referring to a dynamic range in a different workbook mr tom Excel Worksheet Functions 6 March 29th 07 08:56 AM
Sumif referring to range names formulas not updating Excel_Still_Stumps_ME Excel Worksheet Functions 1 September 19th 06 08:14 PM
Range selecting in non-active workbook SJC[_2_] Excel Programming 3 December 30th 05 01:55 PM
hidden names in active workbook hamcdo Excel Worksheet Functions 2 June 1st 05 05:46 PM
Get range value active workbook on open add-in Ajtb Excel Programming 1 February 11th 05 01:52 PM


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