Deleting all Range Names except Print_Area?

N

Nodak

I am trying to delete all Named Ranges Except "Print_Area" is there a way to
accomplish this? the code below deletes "Print_Area"..

Sub DeleteNames()
Dim ThisName As Name
For Each ThisName In ActiveWorkbook.Names
If ThisName <> "Print_Area" Then ThisName.Delete
Next ThisName

End Sub
 
D

Dave Peterson

Option Explicit
Sub DeleteNames()
Dim ThisName As Name
For Each ThisName In ActiveWorkbook.Names
If LCase(ThisName.Name) Like LCase("*!Print_Area") Then
'do nothing
Else
ThisName.Delete
End If
Next ThisName

End Sub

But I'd be careful. There are other names that excel uses, too.

You may want to get a copy of Jan Karel Pieterse's (with
Charles Williams and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

You may see some names that you want to add.

* is a wild card
! because print_area is a worksheet level name. The name could be
sheet1!print_area.
lcase() just because text comparisons make me nervous.
 

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