Delete all the names

ChrisUK

Well-known Member
Joined
Sep 3, 2002
Messages
675
Hi,

I have a workbook with hundreds of names in it, how do I delete them all please? There must be an easy way!

TIA

Chris
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Sub DeleteAllNames()
Dim nName As Name
For Each nName In Names
nName.Delete
Next nName
End Sub
 
Upvote 0
Code:
Sub DeleteSelectedNames()
'========================================================================
' THIS DELETES ALL NAMES FROM WORKBOOK OR SHEET WITH AN X IN COLUMN C NEXT TO NAME SPECIFIED COL B
' NAMES ARE ON LIST ACTIVESHEET THAT WAS CREATED BY listnms CODE BELOW
'
'========================================================================
    Dim CurrentSheet As Worksheet
    Dim ws As Worksheet
    Dim nm As String
    '-------------------------------------------------
    On Error Resume Next    ' in case name does not exist
    Set CurrentSheet = ActiveSheet
    '- loop list
    For c = 1 To 1000
        If CurrentSheet.Cells(c, 3).Value = "X" Then
            nm = CurrentSheet.Cells(c, 1).Value
    '-----------------------------------------
    '- workbook level name
            ActiveWorkbook.Names(nm).Delete
    '-----------------------------------------
    '- worksheet level name
            For Each ws In Worksheets
                ws.Names(nm).Delete
            Next
    '-----------------------------------------
        End If
    Next c
    '-------------------------------------------------
    MsgBox ("Done")
End Sub
Sub listnms()
'========================================================================
' THIS CREATES A LIST OF NAMED RANGES
' ****MUST BE IN WORKBOOK OR PERSONAL****
'========================================================================
    Sheets.Add Before:=Sheets(1)
    n = ActiveSheet.Name
    Worksheets(n).Range("A1").ListNames
    Columns("A:A").ColumnWidth = 15
    Columns("B:B").ColumnWidth = 51
End Sub

Or
Code:
Sub RemoveNamesInWorkbook()
''========================================================================
'' THIS DELETES ALL NAMES FROM WORKBOOK APART FROM "Print_Area"
''========================================================================
    Const strKeepThisName As String * 10 = "Print_Area"
    Dim nm As Name
    For Each nm In ActiveWorkbook.Names
        If Not nm.Name Like "*" & strKeepThisName Then nm.Delete
    Next
    Set nm = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,060
Messages
6,053,305
Members
444,651
Latest member
markkuznetsov1

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