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 ***