Deleting non-existent 'Names'

mach3

Board Regular
Joined
Mar 24, 2002
Messages
245
i have a simple macro that creates Names. however, when a worksheet(s) that contains references to a Name is deleted, the list of Names in the Define Names box still contains a listing of that name. However, the reference to that Name is #ref'd (e.g., '#REF!$A$1).

since users of this excel file will be creating/deleting many worksheets, there will be a long list of un-used, un-referenced, 'dead' Names.

#1 - is there a maximum # of Names allowed? i don't want users to exceed this limit and crash the tool.

#2 - even if #1 is not a concern, managing a long list of Names (of which a vast majority will be junk) is not a good thing. can someone offer up a short macro that checks for bogus Names and deletes them from the Names list?

thanks for your attention.


mach3
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
1. Limited only by the available memory on the PC.
 
Upvote 0
Hi Mac

Run this code on open or close etc

Code:
Sub DeleteREFnames()
Dim nmRef As Name
 
 For Each nmRef In ActiveWorkbook.Names
   If Left(nmRef.RefersTo, 5) = "=#REF" Then nmRef.Delete
 Next
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,161
Members
448,948
Latest member
spamiki

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