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.
by Allen Wyatt
(last updated August 1, 2015)
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:
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.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
If you lose your place on the screen quite often, you might find it helpful to have not just a single cell highlighted, ...Discover More
Sometimes, getting numbers from a program into Excel, using the formatting you want, can be a challenge. This tip ...Discover More
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
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.