Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Deleting Names in a Workbook

Hello,
I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid. My thought was to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Deleting Names in a Workbook

i couldn't get the iserror to work for me

give this a try

Sub name_ranges3()
Dim nm As Name
On Error Resume Next
For Each nm In ThisWorkbook.Names
If Left(nm, 5) = "=#REF" Then
nm.Delete
End If
Next nm


End Sub


--


Gary


"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid. My thought was to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Deleting Names in a Workbook

try this,- delete all names

Sub DelNames()
Dim x
For Each x In ActiveWorkbook.Names
ActiveWorkbook.Names(x.Name).Delete
Next
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Deleting Names in a Workbook

On Sat, 02 Sep 2006 08:05:05 -0700, Bill wrote:

I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid.


Valid? I think you mean invalid. How about something like this?

Sub DeleteOldRangeNames()
Dim RN As Name
For Each RN In ActiveWorkbook.Names
If InStr(1, RN.RefersTo, "#REF", vbTextCompare) Then
RN.Delete
End If
Next RN
End Sub

Don <www.donwiss.com (e-mail link at home page bottom).
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deleting Names in a Workbook

If you're developing a workbook (a one time thing), you may want to use Jan
Karel Pieterse's (with Charles Williams and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

Heck, if you use names, this will make you're life easier.


Bill wrote:

Hello,
I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid. My thought was to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Deleting Names in a Workbook

Sub DeleteInvalidNames()

Dim oName As Name
Dim strAddress As String

On Error Resume Next

For Each oName In ActiveWorkbook.Names
strAddress = oName.RefersToRange.Address
If Len(strAddress) = 0 Then
oName.Delete
End If
Next

End Sub


RBS


"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid. My thought was to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deleting Names in a Workbook

There are names that don't refer to ranges that will be deleted with this
routine.

RB Smissaert wrote:

Sub DeleteInvalidNames()

Dim oName As Name
Dim strAddress As String

On Error Resume Next

For Each oName In ActiveWorkbook.Names
strAddress = oName.RefersToRange.Address
If Len(strAddress) = 0 Then
oName.Delete
End If
Next

End Sub

RBS

"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid. My thought was to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Deleting Names in a Workbook

Yes, true, hadn't thought about that.

RBS

"Dave Peterson" wrote in message
...
There are names that don't refer to ranges that will be deleted with this
routine.

RB Smissaert wrote:

Sub DeleteInvalidNames()

Dim oName As Name
Dim strAddress As String

On Error Resume Next

For Each oName In ActiveWorkbook.Names
strAddress = oName.RefersToRange.Address
If Len(strAddress) = 0 Then
oName.Delete
End If
Next

End Sub

RBS

"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the
names
remain. I would like to delete those that are valid. My thought was
to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deleting Names in a Workbook

That's one of the reasons I'll use Jan Karel (and others) addin. They have so
many things that I would have never thought about already built in.

The bad news is that sometimes you just have to have your own code clean up a
mess.

RB Smissaert wrote:

Yes, true, hadn't thought about that.

RBS

"Dave Peterson" wrote in message
...
There are names that don't refer to ranges that will be deleted with this
routine.

RB Smissaert wrote:

Sub DeleteInvalidNames()

Dim oName As Name
Dim strAddress As String

On Error Resume Next

For Each oName In ActiveWorkbook.Names
strAddress = oName.RefersToRange.Address
If Len(strAddress) = 0 Then
oName.Delete
End If
Next

End Sub

RBS

"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the
names
remain. I would like to delete those that are valid. My thought was
to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Deleting Names in a Workbook

Names can refer to multi-areas any one of which might be missing. To cater
suggest change -

If Left(nm, 5) = "=#REF" Then

to
If InStr(nm.RefersTo, "#REF!") Then

I posted a full demo in this ng
subject: "Delete broken named ranges in sheet"
date: 15 August 2005

but for some reason I cannot find it in Google

The best solution though is as referred to by Dave Peterson in this thread.

Regards,
Peter T

"GKeramidas" wrote in message
...
i couldn't get the iserror to work for me

give this a try

Sub name_ranges3()
Dim nm As Name
On Error Resume Next
For Each nm In ThisWorkbook.Names
If Left(nm, 5) = "=#REF" Then
nm.Delete
End If
Next nm


End Sub


--


Gary


"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the names
remain. I would like to delete those that are valid. My thought was to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Deleting Names in a Workbook

but for some reason I cannot find it in Google

Google Groups seems to have lost it, very strange. But Google finds it in
other places, eg

http://www.mailarchive.ca/lists/micr...ming/2005-08/5
120.html

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
Names can refer to multi-areas any one of which might be missing. To cater
suggest change -

If Left(nm, 5) = "=#REF" Then

to
If InStr(nm.RefersTo, "#REF!") Then

I posted a full demo in this ng
subject: "Delete broken named ranges in sheet"
date: 15 August 2005

but for some reason I cannot find it in Google

The best solution though is as referred to by Dave Peterson in this

thread.

Regards,
Peter T

"GKeramidas" wrote in message
...
i couldn't get the iserror to work for me

give this a try

Sub name_ranges3()
Dim nm As Name
On Error Resume Next
For Each nm In ThisWorkbook.Names
If Left(nm, 5) = "=#REF" Then
nm.Delete
End If
Next nm


End Sub


--


Gary


"Bill" wrote in message
...
Hello,
I use names a lot in a workbook. When a worksheet is deleted, the

names
remain. I would like to delete those that are valid. My thought was

to
cycle through the names and try to go to the name. If an error is
caused, then delete the name. I used the code below but every name is
deleted. What am I doing wrong or is there an easier way to do this.

Thanks

Bill

Sub RemoveNamesNotThere()
nm = ActiveWorkbook.Names.Count
On Error GoTo 0
For j = nm To 1 Step -1
On Error Resume Next
NN = ActiveWorkbook.Names(j)
Application.Goto Reference:=NN
If Err < 0 Then
ActiveWorkbook.Names(j).Delete
End If
On Error GoTo 0
Next j
CS.Activate
End Sub


*** Sent via Developersdex http://www.developersdex.com ***






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 names from the name box Amy C Excel Discussion (Misc queries) 4 May 12th 06 11:00 AM
Deleting unused Defined Names in a workbook? Mike Piazza Excel Programming 0 May 13th 05 03:18 PM
Deleting Names Rob Bovey Excel Programming 0 September 14th 04 08:30 PM
Deleting workbook names w/ VB Big-E Excel Programming 6 April 28th 04 07:01 PM
deleting workbook names in excel Liz Gewirtz Excel Programming 1 November 7th 03 01:42 PM


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