LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default find workbook names that are in sheet

Needed a function that finds the Workbook level names
that are in a specified sheet and have put something together, but have a
feeling that there is a better (less code) way to handle this:

Function GetSheetNamedRanges(oSheet As Worksheet) As Variant

'this picks up workbook names that are in the specified sheet
'will need to test for no names found in specified sheet by doing:
'If IsArray(arr) Then
'-----------------------------------------------------------------
Dim i As Long
Dim na As Name
Dim rngSheet As Range
Dim collNames As Collection
Dim arrNames

If ActiveWorkbook.Names.Count 0 Then

With oSheet
Set rngSheet = .Range(.Cells(1), .Cells(.Rows.Count, Columns.Count))
End With

Set collNames = New Collection

On Error Resume Next
For Each na In ActiveWorkbook.Names
If Not Application.Intersect(rngSheet, Range(na.Name)) Is Nothing Then
If Err.Number = 0 Then
collNames.Add na.Name
i = i + 1
Else
Err.Clear
End If
End If
Next na

If i 0 Then
ReDim arrNames(1 To i)
For i = 1 To i
arrNames(i) = collNames(i)
Next
GetSheetNamedRanges = arrNames
End If

End If

End Function


Any suggestions to improve on this?


RBS

 
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
sheet names displayed in first workbook sheet help Dingy101 Excel Programming 9 December 5th 09 12:01 PM
Find and Replace Sheet names FARAZ QURESHI Excel Discussion (Misc queries) 2 February 23rd 09 01:40 AM
Using Sheet names & Workbook names in VBA coding Colin Foster[_5_] Excel Programming 5 July 7th 06 07:04 PM
Run macro to find names on seperate workbook, then add info from t Tim Excel Discussion (Misc queries) 1 March 22nd 06 03:47 PM
how do I find names in a workbook full of names aj Excel Discussion (Misc queries) 1 January 19th 06 09:01 PM


All times are GMT +1. The time now is 09:31 PM.

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

About Us

"It's about Microsoft Excel"