How to delete all defined names?

cganivet

Board Regular
Joined
Feb 12, 2006
Messages
183
Hello gurus.

I need to know to remove all of the defined names in a spreadsheet (the ones found in "Insert-->Name-->Define"). In the task I have, I have no way of knowing how many names there are or what their names are. So I would just like a function which deletes all at once, no matter what they are.

thank you for your help.
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Code:
Sub Test()
For Each n in Thisworkbook.Names
   n.Delete
Next n
End Sub

Best regards

Richard
 

ziggyo

New Member
Joined
Apr 24, 2007
Messages
6
What if I wanted to delete all defined names in a selected column? How would this be done?
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832

ADVERTISEMENT

Hi, ziggyo
Welcome to the Board !!!!!

this works for me
Code:
Sub test()
'Erik Van Geit
'070427
Dim n As Name
Dim rng As Range
Dim checkrng As Range

Set rng = Sheets(1).Columns(1)

On Error Resume Next    'there might be names which do not refer to ranges

    For Each n In ThisWorkbook.Names
        With n
        Set checkrng = Nothing
        Set checkrng = Intersect(Range(.RefersTo), rng)
        'you might want to use something else than intersect
        If Not checkrng Is Nothing Then n.Delete
        End With
    Next n

End Sub
 

ziggyo

New Member
Joined
Apr 24, 2007
Messages
6
Hey thanks Erik. I tested your code and it didn't seem to do what I wanted. Below is modified from what you did. Not sure if this would be correct. But basically I am wanting to check sheet "COA" column "AO" for any defined names. If found, then delete all.

Code:
Sub test()
'Erik Van Geit
'070427
Dim n As Name
Dim rng As Range
Dim checkrng As Range

Set rng = Sheets("COA").Columns("AO:AO")

On Error Resume Next    'there might be names which do not refer to ranges

    For Each n In ThisWorkbook.Names
        With n
        Set checkrng = Nothing
        Set checkrng = Intersect(Range(.RefersTo), rng)
        'you might want to use something else than intersect
        If Not checkrng Is Nothing Then n.Delete
        End With
    Next n

End Sub

And no this also didn't work :(
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
the code works for me: all names ranges which have an intersection with the defined column are deleted

what do you mean by "didn't work" anyway ? that's a very general expression :confused:

is it in a normal module, not a sheetmodule?
are you sure the column is the one you need?
are you sure we are talking about NAMED RANGES?!!

if still not working, explain step by step what the problem is
 

Watch MrExcel Video

Forum statistics

Threads
1,114,059
Messages
5,545,758
Members
410,704
Latest member
Cobber2008
Top