View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
John[_88_] John[_88_] is offline
external usenet poster
 
Posts: 205
Default Macro to delete names except Print_Area

Dear Barber,

Have a go with the code below. The Print_Range name gets prefixed with the
sheet it applies to so you need to use the 'Right' function to check the
last part of the returned string. So what it's saying is if the last 10
characters of each name do not end in "Print_Area" then delete them. (You
can delete the Debug.Print... line which just shows you what's going on in
the Intermediate window of the VBE.)

Best regards

John

Sub DeleteNames()
' Gets rid of all named ranges
Dim nName As Name

For Each nName In Names
Debug.Print nName.Name
If Right(nName.Name, 10) < "Print_Area" Then
nName.Delete
End If
Next nName

End Sub

wrote in message
ups.com...
I have a macro that deletes all of the named ranges in my workbook. The
problem is that it also deletes the "Print_Area" range, which results
in resetting my print area.

Is there a way to modify this so that it will keep my old print area?

Sub DeleteNames()
'
' Gets rid of all named ranges
'
For Each nName In Names
nName.Delete
Next
'
End Sub