Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Finding Unused Names.

Finding Unused Names

Written by Allen Wyatt (last updated November 4, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


4

Richard has a workbook that he's been using for a while, and it has quite a few names in it (named ranges, named formulas, etc.). He wonders if there is an easy way to find names that are not used at all, as he'd like to get rid of those names.

There is no built-in way to get rid of these unused names. You can, however, create a macro that will do the trick for you. This is most easily done by using the Find method to figure out which names have references that can be "found." If the reference cannot be found, then the name is not in use.

Sub RidOfNames()
    Dim myName As Name
    Dim fdMsg As String

    On Error Resume Next
    fdMsg = ""
    For Each myName In Names
        If Cells.Find(What:=myName.Name, _
          After:=ActiveCell, _
          LookIn:=xlFormulas, _
          LookAt:=xlPart, _
          SearchOrder:=xlByRows, _
          SearchDirection:=xlNext, _
          MatchCase:=False, _
          SearchFormat:=False).Activate = False Then
            fdMsg = fdMsg & myName.Name & vbCr
            ActiveWorkbook.Names(myName.Name).Delete
        End If
    Next myName
    If fdMsg = "" Then
        MsgBox "No unused names found in the workbook"
    Else
        MsgBox "Names Deleted:" & vbCr & fdMsg
    End If
End Sub

The macro steps through all the elements of the Names collection and does a search for each name. If the name cannot be found, then the name is deleted. When the macro is completed, it displays a message box that lists the names that were removed from the workbook.

There are problems with the RidOfNames macro, though. It doesn't check everywhere that a name might be used. For instance, it doesn't determine if names are referenced in a macro or if they are used on other worksheets (including hidden worksheets) in your workbook. It also doesn't check to see if a particular name is used in a conditional formatting rule or in charts, drop-down lists, and other objects. So, it is possible that the macro could delete names you really do need to keep. (This means you should be careful and run it only on a workbook you hae backed up elsewhere.) Even with the drawbacks, RidOfNames can work wonders in simple workbooks that don't have other macros (besides this one) and that contain most of their data on a single worksheet.

If you would rather not create your own macro, you can opt to use a free add-in by Jan Karel Pieterse. The add-in, called Name Manager, allows you to (guess what?) manage names better than you can do with native Excel. One of the functions it provides is the ability to get rid of names that are no longer needed. You can find the add-in here:

https://jkp-ads.com/excel-name-manager.asp

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10998) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Finding Unused Names.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Moving Table Rows Quickly

One of the most esoteric shortcuts available in Word is one that allows you to move table rows, either within a table or ...

Discover More

Adjusting Row Height when Wrapping Text

If you have some cells merged in a worksheet, and you wrap text within that merged cell, Excel won't automatically resize ...

Discover More

Using Data Validation

Want to control what users put into a cell? It's easy to do using a feature called data validation, as described in this tip.

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Deleting Rows before a Cutoff Date

If you are using Excel to work with data that is date-centered, you may want to delete some of the data before a specific ...

Discover More

How Many Rows and Columns Have I Selected?

Want a quick way to tell how may rows and columns you've selected? Here's what I do when I need to know that information.

Discover More

Mouse Scroll Wheel Doesn't Work when Editing Formulas

Using your mouse to select cells for inclusion in a formula can be an exercise in futility on some systems. Here's why ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven minus 2?

2023-11-06 12:48:07

Alex

@Willy Thanks for making sure anyone who missed this section of the article will pay particular attention:

"There are problems with the RidOfNames macro, though. It doesn't check everywhere that a name might be used. For instance, it doesn't determine if names are referenced in a macro or if they are used on other worksheets (including hidden worksheets) in your workbook. It also doesn't check to see if a particular name is used in a conditional formatting rule or in charts, drop-down lists, and other objects. So, it is possible that the macro could delete names you really do need to keep. (This means you should be careful and run it only on a workbook you hve backed up elsewhere.)"


2023-11-05 15:00:24

J. Woolley

My Excel Toolbox's NamesInFormulas macro lists hyperlinks to formula cells referencing each visible defined name (named range) in the active workbook. (Hidden names are ignored.) The cell's formula will be included in a comment attached to its hyperlink. The following details are also provided for each name: Scope, Name, Refers To, Value, and Comment. Results are recorded in the active workbook's 'NamesIn...' worksheet.
My Excel Toolbox also includes the following dynamic array function to list defined names with workbook, worksheet, or any scope, including names that are normally hidden:
=ListNames([Scope],[SkipHidden],[SkipHeader])
The list includes these columns: Scope, Name, Visible, Refers To, Value, Comment. If Refers To and Value are both #REF! the name can probably be deleted.
Reviewing results from the NamesInFormulas macro and the ListNames function might help decide which names are unused, but first consider Willy Vanhaelen's comment below. The NamesInFormulas macro does not detect names used in charts, conditional formats, data validation, external workbooks, VBA procedures, etc.
When using pre-2021 versions of Excel without support for dynamic arrays, consider UseSpillArray.pdf.
See https://sites.google.com/view/MyExcelToolbox


2023-11-04 09:33:10

Ron S

There is another tip with similar macros
https://excelribbon.tips.net/T010338_Getting_Rid_of_Unused_Range_Names.html


2023-11-04 06:17:33

Willy Vanhaelen

THIS IS A VERY DANGEROUS MACRO. I tested it in a workbook with many names and it deleted most of them because they were only used in vba code. It also deleted one used in a conditional format form


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.