PC Review


Reply
Thread Tools Rate Thread

Delete defined names with errors using VBA

 
 
MikeM_work
Guest
Posts: n/a
 
      25th Aug 2009
Using this code snippet from Microsoft (that I modified slightly), I can
delete any and all defined names without errors.
Any defined name that has a #REF! error, for example, cannot be deleted with
the VBA.

Is there any VBA code that will delete defined names with errors?

Thanks!

Mike


Sub DELETE_VISIBLE_Names()

' Dimension variables.
Dim xName As Variant
Dim Result As Variant
Dim Vis As Variant

' Loop once for each name in the workbook.
For Each xName In ActiveWorkbook.Names

'If a name is not visible (it is hidden)...
If xName.Visible = True Then
Vis = "Visible"
Else
Vis = "Hidden"
End If

If Vis = "Visible" Then xName.Delete

' Loop to the next name.
Next xName

End Sub
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      25th Aug 2009
Can you show us an example that does not delete? I just tried it with a
Defined Name that covered a range of COUNTIF formulas where the range part
of some of the COUNTIF statements were #REF! and I was able to delete that
Defined Name.

--
Rick (MVP - Excel)


"MikeM_work" <(E-Mail Removed)> wrote in message
news:3D44AD90-3E66-4CE4-AE7E-(E-Mail Removed)...
> Using this code snippet from Microsoft (that I modified slightly), I can
> delete any and all defined names without errors.
> Any defined name that has a #REF! error, for example, cannot be deleted
> with
> the VBA.
>
> Is there any VBA code that will delete defined names with errors?
>
> Thanks!
>
> Mike
>
>
> Sub DELETE_VISIBLE_Names()
>
> ' Dimension variables.
> Dim xName As Variant
> Dim Result As Variant
> Dim Vis As Variant
>
> ' Loop once for each name in the workbook.
> For Each xName In ActiveWorkbook.Names
>
> 'If a name is not visible (it is hidden)...
> If xName.Visible = True Then
> Vis = "Visible"
> Else
> Vis = "Hidden"
> End If
>
> If Vis = "Visible" Then xName.Delete
>
> ' Loop to the next name.
> Next xName
>
> End Sub


 
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
Delete defined names beata Microsoft Excel Misc 1 7th Jan 2008 09:44 PM
delete defined names =?Utf-8?B?VG9kZA==?= Microsoft Excel Programming 4 6th Mar 2006 08:10 PM
How to delete all defined names from a workbook? Dmitry Kopnichev Microsoft Excel Discussion 15 14th Nov 2005 03:26 PM
How to delete all defined names from a workbook? Dmitry Kopnichev Microsoft Excel Worksheet Functions 15 14th Nov 2005 03:26 PM
Macro to delete Defined Names =?Utf-8?B?TWlrZSBQaWF6emE=?= Microsoft Excel Programming 1 13th May 2005 06:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 PM.