+ Reply to Thread
Results 1 to 6 of 6

Deleting Broken Defined Name

Hybrid View

polishfc Deleting Broken Defined Name 01-21-2022, 06:25 PM
TMS Re: Deleting Broken Defined... 01-21-2022, 08:44 PM
polishfc Named Range #REF Delete 01-22-2022, 10:10 PM
davesexcel Re: Named Range #REF Delete 01-23-2022, 07:13 AM
TMS Re: Named Range #REF Delete 01-23-2022, 07:19 AM
Glenn Kennedy Re: Deleting Broken Defined... 01-23-2022, 07:28 AM
  1. #1
    Registered User
    Join Date
    11-12-2019
    Location
    New York
    MS-Off Ver
    2016
    Posts
    16

    Question Deleting Broken Defined Name

    I have large model that over the years accumulated a lot of name ranges, to the point that the name manager will not open.

    Most of the solutions that I found so far are not working to get the numbers of defined names down. I was hoping to run this code; however, I run into a memory error:


    Sub DeleteNamedRangesWithREF()
        Dim nm As Name
        For Each nm In ActiveWorkbook.Names
            If InStr(nm.Value, "#REF!") > 0 Then
                nm.Delete
            End If
        Next nm
    End Sub
    I also don't fully know which name ranges are needed versus not (or least by defined name) so a total delete of the list or a specific, delete anything that contains x,y,z would be difficult so ideally would want to stick with the delete any errors and hope name manager opens by then. None the less open to other suggestions.

    Thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,102

    Re: Deleting Broken Defined Name

    See if this helps locate the problem Named Ranges.

    Option Explicit
    
    Sub ListNamedRanges()
    
    Dim nm As Name, vArray, i As Long
    
    ' pick somewhere to output the details
    Dim rOutput As Range
    Set rOutput = Range("F1")   ' adjust as required
    
    'Debug.Print ThisWorkbook.Names.Count
    If ThisWorkbook.Names.Count = 0 Then Exit Sub
    
    ' resize the array to store the names and references
    ReDim vArray(1 To ThisWorkbook.Names.Count, 1 To 4)
    
    ' loop through the names in the workbook
    For Each nm In ThisWorkbook.Names
        'Debug.Print nm.Name, nm.RefersTo, nm.Value
        i = i + 1
        vArray(i, 1) = nm.Name
        vArray(i, 2) = nm.RefersTo
        vArray(i, 3) = nm.Value
        If InStr(nm.Value, "#REF!") > 0 Then
            vArray(i, 4) = "check"
        End If
    Next 'i
    
    ' output the array of Name details
    With rOutput
        .Resize(, 4).Value = Array("Name", "Refers to", "Value", "Check")
        With .Offset(1).Resize(ThisWorkbook.Names.Count, 4)
            .NumberFormat = "@"
            .Value = vArray
        End With
    End With
    
    End Sub
    Sample output

    HTML Code: 
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-12-2019
    Location
    New York
    MS-Off Ver
    2016
    Posts
    16

    Question Named Range #REF Delete

    I've been using the following code to get the the number of defined name ranged down to a manageable list (e.g., being able to open name range manager):

    Sub DeleteAllREFRanges()
      Dim n As Name
      
      For Each n In ActiveWorkbook.Names
        If InStr(n.Value, "#REF!") > 0 Then n.Delete
      Next n
    
    End Sub
    In a recent hand me down file with a significant amount of stalled name ranged, I get an "out of memory" (7) error. Any recommendations on code alterations to make it run?

    Thanks

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Named Range #REF Delete

    You may need to loop through it by names count.

        Dim n As Name, x As Long
      
        For x = ActiveWorkbook.Names.Count To 1 Step -1
            Set n = ActiveWorkbook.Names(x)
            If InStr(n, "#REF!") > 0 Then
                n.Delete
            End If
        Next x

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,102

    Re: Named Range #REF Delete

    Did my answer in your previous thread help at all?

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Deleting Broken Defined Name

    Administrative Note:

    Welcome to the forum.

    Unfortunately, this is a duplicate thread, and you are allowed only ONE thread per issue here.

    Please see Forum Rule #5 about thread duplication.

    I have merged both threads to prevent confusion.


    DO NOT duplicate threads in future.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Deleting Excel Defined Names
    By diannal82 in forum Excel General
    Replies: 4
    Last Post: 09-01-2015, 04:59 PM
  2. Broken list after deleting list item
    By zipzapboink in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-02-2010, 10:18 AM
  3. Deleting a defined range name?
    By gdallas in forum Excel General
    Replies: 5
    Last Post: 02-17-2010, 08:15 AM
  4. Deleting rows NOT containing defined values
    By arthurbr in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-24-2008, 07:50 AM
  5. Deleting rows to a defined point
    By Tim Green in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2006, 12:00 PM
  6. [SOLVED] auto deleting defined rows
    By LoriM in forum Excel General
    Replies: 4
    Last Post: 08-04-2005, 02:05 PM
  7. Deleting unused Defined Names in a workbook?
    By Mike Piazza in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2005, 01:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1