Delete all Named Ranges except PrintArea

  • Thread starter Thread starter DoctorV
  • Start date Start date
D

DoctorV

I have the following function that just needs a slight tweak. I need t
delete all Named ranges EXCEPT for PrintArea. What do I need to do t
adjust this Macro so that it does not delete the Named Range fo
PrintArea. Thanks

Sub DeletePhantomRangeNames()

For Each nm In ActiveWorkbook.Names

nm.Delete

Next nm

End Su
 
Doc,

Dim nm As Name

For Each nm In ActiveWorkbook.Names
If Not Right(nm.Name, 10) = "Print_Area" Then nm.Delete
Next nm
 
How about:

Option Explicit
Sub DeletePhantomRangeNames()
Dim nm As Name
For Each nm In ActiveWorkbook.Names
If LCase(nm.Name) Like "!print_area" Then
'do nothing
Else
nm.Delete
End If
Next nm
End Sub


And if you're working with names a lot, do yourself a big favor and download Jan
Karel Pieterse's (with Charles Williams and Matthew Henson) Name Manager.

You can find it at:
NameManager.Zip from http://www.bmsltd.ie/mvp
 
Back
Top