Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Deleting Named Ranges

Hi

I hope someone can help me ou there. I'm trying to delete all named ranges
in all Worksheets, except one named "Connection Data", but I don't seem to
having any success. I have pasted my code below. If anyone can enlighten me
as to where I'm going wrong, it would be much appreciated.

Many Thanks - Grant

Sub DeleteRanges()
Dim WSh As Worksheet
Dim nm As Name

'----------------------------
'Delete All Named Ranges Except Named Ranges "In Connection Data" Workbook
'----------------------------

For Each WSh In ThisWorkbook.Worksheets
If Not WSh.Name Like "Connection Data" Then
For Each nm In ActiveWorkbook.Names
nm.Delete
Next nm
End If
Next WSh

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting Named Ranges

For Each nm In ActiveWorkbook.Names
if instr(1,nm.Refersto,"Connection Data",vbTextCompare) = 0 then
nm.Delete
end if
Next nm

Might be what you want.

--
Regards,
Tom Ogilvy


"Grant Reid" wrote in message
...
Hi

I hope someone can help me ou there. I'm trying to delete all named ranges
in all Worksheets, except one named "Connection Data", but I don't seem to
having any success. I have pasted my code below. If anyone can enlighten

me
as to where I'm going wrong, it would be much appreciated.

Many Thanks - Grant

Sub DeleteRanges()
Dim WSh As Worksheet
Dim nm As Name

'----------------------------
'Delete All Named Ranges Except Named Ranges "In Connection Data" Workbook
'----------------------------

For Each WSh In ThisWorkbook.Worksheets
If Not WSh.Name Like "Connection Data" Then
For Each nm In ActiveWorkbook.Names
nm.Delete
Next nm
End If
Next WSh

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting Named Ranges

I believe your if statement is misplaced and you name the name property to
get the name and not the address. Try this:

Sub DeleteRanges()
Dim WSh As Worksheet
Dim nm As Name

'----------------------------
'Delete All Named Ranges Except Named Ranges "In Connection Data" Workbook
'----------------------------

For Each WSh In ThisWorkbook.Worksheets

For Each nm In ActiveWorkbook.Names

If Not nm.Name Like "Connection Data" Then

nm.Delete
End If
Next nm

Next WSh

End Sub



Bob L.

"Grant Reid" wrote in message
...
Hi

I hope someone can help me ou there. I'm trying to delete all named ranges
in all Worksheets, except one named "Connection Data", but I don't seem to
having any success. I have pasted my code below. If anyone can enlighten
me
as to where I'm going wrong, it would be much appreciated.

Many Thanks - Grant

Sub DeleteRanges()
Dim WSh As Worksheet
Dim nm As Name

'----------------------------
'Delete All Named Ranges Except Named Ranges "In Connection Data" Workbook
'----------------------------

For Each WSh In ThisWorkbook.Worksheets
If Not WSh.Name Like "Connection Data" Then
For Each nm In ActiveWorkbook.Names
nm.Delete
Next nm
End If
Next WSh

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Deleting Named Ranges

Hi Tom

Thanks for your response. Its not quite what I need though, perhaps I
couched my question incorrectly. What I actually am attempting to do is to
loop through all Worksheets, except "Connection Data" and delete all named
ranges. So utlimately, the only named ranges remaining will be the named
ranges in the Worksheet "Connection Data".

Many Thanks - Grant


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting Named Ranges

You have to define what you mean by named ranges in the Worksheet
"Connection Data".

If you mean named ranges that refer to ranges in the worksheet "Connection
Data", then I gave you a solution.

If you mean named ranges that are utilized in formulas found in the
worksheet "Connection Data", then you have much more work to do.

If you are talking about sheet level names, then you shouldn't be looping in
the ActiveWorkbook.Names collection.

--
Regards,
Tom Ogilvy

"Grant Reid" wrote in message
...
Hi Tom

Thanks for your response. Its not quite what I need though, perhaps I
couched my question incorrectly. What I actually am attempting to do is to
loop through all Worksheets, except "Connection Data" and delete all named
ranges. So utlimately, the only named ranges remaining will be the named
ranges in the Worksheet "Connection Data".

Many Thanks - Grant






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Deleting Named Ranges

Hi

Many thanks to you Tom and Bob. I managed to figure it out myself - its been
a loooong day.

Kind Regards - Grant


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
Deleting all named ranges that have a workbook scope Babymech Excel Discussion (Misc queries) 3 February 19th 09 04:21 PM
deleting multiple named ranges april Excel Discussion (Misc queries) 1 April 15th 08 07:03 PM
problem in deleting the named ranges Maya[_2_] Excel Worksheet Functions 1 June 28th 07 12:52 PM
Deleting Named Ranges Carl Excel Worksheet Functions 2 August 31st 06 07:16 PM
Deleting many named ranges Tom Hayakawa Excel Worksheet Functions 2 March 28th 05 10:47 PM


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