Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Deleting non-existent 'Names'

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    245
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  2. #2
    MrExcel MVP Anne Troy's Avatar
    Join Date
    Feb 2002
    Location
    Westwood NJ
    Posts
    2,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    1. Limited only by the available memory on the PC.
    ~Anne Troy

  3. #3
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Posts
    245
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    thanks. i just added the macro to an existing macro and works fine.

    mach3

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •