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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
What if I wanted to delete all defined names in a selected column? How would this be done?
 
Upvote 0
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
 
Upvote 0
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 :(
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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
Back
Top