PC Review


Reply
Thread Tools Rate Thread

How can I delete all named ranges in a workbook or worksheet?

 
 
AZSteve
Guest
Posts: n/a
 
      21st Oct 2009
I have 5-15 sheets in a workbook and I want to delete all the names (25 or
so) in each sheet in the workbook. I have not figured out a way to do this
reliably yet with a macro. Then I need to do it again on the next workbook.
Suggestions?
 
Reply With Quote
 
 
 
 
Sam Wilson
Guest
Posts: n/a
 
      21st Oct 2009
Sub test()

Dim ws As Worksheet
Dim nm As Name

For Each ws In Worksheets
For Each nm In ws.Names
nm.Delete
Next nm
Next ws

End Sub


"AZSteve" wrote:

> I have 5-15 sheets in a workbook and I want to delete all the names (25 or
> so) in each sheet in the workbook. I have not figured out a way to do this
> reliably yet with a macro. Then I need to do it again on the next workbook.
> Suggestions?

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      21st Oct 2009
Try the below

Sub DeleteNames()
Dim nmRange As Name
For Each nmRange In ActiveWorkbook.Names
nmRange.Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"AZSteve" wrote:

> I have 5-15 sheets in a workbook and I want to delete all the names (25 or
> so) in each sheet in the workbook. I have not figured out a way to do this
> reliably yet with a macro. Then I need to do it again on the next workbook.
> Suggestions?

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      21st Oct 2009
There appear to be certain range names that you should not delete, so here
is a macro that preserves them if they are present and deletes all the
rest...

Sub DeleteNames()
' First seen posted by Bob Phillips
Dim N As Name
For Each N In ActiveWorkbook.Names
If N.Name Like "*_FilterDatabase" Or _
N.Name Like "*Print_Area" Or _
N.Name Like "*Print_Titles" Or _
N.Name Like "*wvu.*" Or _
N.Name Like "*wrn.*" Or _
N.Name Like "*!Criteria" Then
Else
N.Delete
End If
Next N
End Sub

--
Rick (MVP - Excel)


"AZSteve" <(E-Mail Removed)> wrote in message
news:813457AE-0D24-4ADB-AA44-(E-Mail Removed)...
>I have 5-15 sheets in a workbook and I want to delete all the names (25 or
> so) in each sheet in the workbook. I have not figured out a way to do
> this
> reliably yet with a macro. Then I need to do it again on the next
> workbook.
> Suggestions?


 
Reply With Quote
 
AZSteve
Guest
Posts: n/a
 
      21st Oct 2009
I want to delete all names, so the other posts gave me that answer. However
I will save yours for when I want to keep certain names. Thanks.

"Rick Rothstein" wrote:

> There appear to be certain range names that you should not delete, so here
> is a macro that preserves them if they are present and deletes all the
> rest...
>
> Sub DeleteNames()
> ' First seen posted by Bob Phillips
> Dim N As Name
> For Each N In ActiveWorkbook.Names
> If N.Name Like "*_FilterDatabase" Or _
> N.Name Like "*Print_Area" Or _
> N.Name Like "*Print_Titles" Or _
> N.Name Like "*wvu.*" Or _
> N.Name Like "*wrn.*" Or _
> N.Name Like "*!Criteria" Then
> Else
> N.Delete
> End If
> Next N
> End Sub
>
> --
> Rick (MVP - Excel)
>
>
> "AZSteve" <(E-Mail Removed)> wrote in message
> news:813457AE-0D24-4ADB-AA44-(E-Mail Removed)...
> >I have 5-15 sheets in a workbook and I want to delete all the names (25 or
> > so) in each sheet in the workbook. I have not figured out a way to do
> > this
> > reliably yet with a macro. Then I need to do it again on the next
> > workbook.
> > Suggestions?

>
> .
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      21st Oct 2009
The list of names that Rick avoided deleting wasn't for names that he assigned.

These are names that excel uses (without your permission and usually without
your knowledge). If you delete any of them, you may be breaking a feature built
into excel.

I'd use Rick's version.

AZSteve wrote:
>
> I want to delete all names, so the other posts gave me that answer. However
> I will save yours for when I want to keep certain names. Thanks.
>
> "Rick Rothstein" wrote:
>
> > There appear to be certain range names that you should not delete, so here
> > is a macro that preserves them if they are present and deletes all the
> > rest...
> >
> > Sub DeleteNames()
> > ' First seen posted by Bob Phillips
> > Dim N As Name
> > For Each N In ActiveWorkbook.Names
> > If N.Name Like "*_FilterDatabase" Or _
> > N.Name Like "*Print_Area" Or _
> > N.Name Like "*Print_Titles" Or _
> > N.Name Like "*wvu.*" Or _
> > N.Name Like "*wrn.*" Or _
> > N.Name Like "*!Criteria" Then
> > Else
> > N.Delete
> > End If
> > Next N
> > End Sub
> >
> > --
> > Rick (MVP - Excel)
> >
> >
> > "AZSteve" <(E-Mail Removed)> wrote in message
> > news:813457AE-0D24-4ADB-AA44-(E-Mail Removed)...
> > >I have 5-15 sheets in a workbook and I want to delete all the names (25 or
> > > so) in each sheet in the workbook. I have not figured out a way to do
> > > this
> > > reliably yet with a macro. Then I need to do it again on the next
> > > workbook.
> > > Suggestions?

> >
> > .
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting named ranges on a worksheet (not workbook) BRC Microsoft Excel Programming 5 10th Jan 2010 12:38 AM
Copy worksheet with named ranges to new workbook and keep names Sandy Microsoft Excel Worksheet Functions 0 11th Jul 2008 04:37 PM
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... christian_spaceman Microsoft Excel Programming 3 24th Dec 2007 01:15 PM
Delete all named ranges in a workbook bevanward@gmail.com Microsoft Excel Programming 3 7th Nov 2006 09:09 AM
named ranges at workbook and worksheet levels mark kubicki Microsoft Excel Programming 5 15th Sep 2004 10:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:47 PM.