View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
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 ***