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.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

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
 

Forum statistics

Threads
1,141,915
Messages
5,709,320
Members
421,628
Latest member
Big Boss

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top