Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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 May 26, 2020)
This tip applies to Excel 2007, 2010, and 2013


5

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. 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:

http://www.jkp-ads.com/OfficeMarketPlaceNM-EN.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, and 2013. 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

Defining and Using Custom Colors

Want to spice up your worksheets with your own custom colors? Here's how to define them easily.

Discover More

Reference Shortcut

Need to modify how a cell reference, in a formula, is constructed? The shortcut described in this tip will help you step ...

Discover More

Creating Categories for Your Table of Authorities

A table of authorities is normally divided into separate sections based on categories you define. Here's how to create ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Ranges on Multiple Worksheets

Referring to a range of cells on the current worksheet is easy. But what if you want to refer to a range on a number of ...

Discover More

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

Default Cell Movement when Deleting

Delete a cell or a range of cells, and Excel needs to figure out how to rearrange the void left by the deletion. You can ...

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 two more than 0?

2020-05-26 08:10:32

Please Read

Based on some of the comments below people don't read an entire tip but just grab code and go. READ the entire tip and it will give you information that you will need to understand shortfalls or dangers of it running.


2017-02-26 05:47:06

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 formula.


2015-12-03 17:25:27

michael adel

Please, please, please add a note at the top of this tip that this works only for the current sheet. Not the 'workbook' as in "Richard has a workbook that he's been using for a while"

I'm afraid someone will see this, copy it and use it and not read the notes at the bottom. (I was almost that person!)


2015-08-03 09:04:48

Caroline

It is possible that your workbook contains named ranges that aren't used in any formula or function but that are necessary for the correct functioning of a macro. You don't want to delete those... I learnt that the hard way :-)


2015-08-01 08:48:09

Barbara

It was hard in excel 2003 to find names and delete those which were not required and a macro was very useful for that. However, since moving to 2007 I have found the name manager quite adequate (Formulas, defined names, name manager). If you sort by 'refers to' by clicking on the header all the names not used with have a reference of #n/a or similar. These can be selected em masse by clicking on the first, hold shift and clicking on the last and deleted.
The macro would be a bit quicker especially if you had several workbooks to sort out.


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.