I am attempting to delete external named ranges after a sheet is copied out of a source workbook (the template). I have tried both the following codes, but neither one does the trick. The code is in ThisWorkbook (not a module), and I have tried it with the code both in the template and the new doc. The new doc is where I want the names to be deleted (there are no #REF names in the template).
Deletes named ranges based on the reference to the source doc:
Deletes named ranges based on a #REF in the value of the range (this is my preferred method):
Deletes named ranges based on the reference to the source doc:
Code:
Sub DelRanges()
Dim nName As Name
For Each nName In Names
If InStr(1, nName.RefersTo, "='T:\Fin_") > 0 Then
nName.Delete
End If
Next nName
End Sub
Deletes named ranges based on a #REF in the value of the range (this is my preferred method):
Code:
Sub DeadRanges()
Dim nName As Name
For Each nName In Names
If InStr(1, nName.Value, "#REF") Then
nName.Delete
End If
Next nName
End Sub