Delete all Named Ranges except PrintArea

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
 
E

Earl Kiosterud

Doc,

Dim nm As Name

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

Dave Peterson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top