Deleting all Range Names except Print_Area?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
Back
Top