Share via

Delete large amount of named ranges in excel workbook

Anonymous
2024-11-05T02:08:32+00:00

I have an excel file with ~140,000 named ranges and I would like to delete all of them. There are too many named ranges to open the name manager and I have already tried a number of VBA scripts to delete them without any success. Does anyone have a method or VBA script that would work to delete this amount of named ranges? Thanks.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2024-11-05T08:40:03+00:00

    Hi, Antonio Nunez1

    Thank you for using Microsoft products and posting them to the community.

    You can try this VBA code (I have tested it and it works fine): (But IMHO, your number is too large, and you may experience lag or crash when using this code)

    Sub DeleteAllNames() 
    
        Dim n As Name 
    
        On Error Resume Next 
    
        For Each n In ActiveWorkbook.Names 
    
            n.Delete 
    
        Next n 
    
        On Error GoTo 0 
    
        MsgBox "All named ranges have been deleted." 
    
    End Sub
    

    I hope the above information can help you. Feel free to send a message if you need further help.

    Best wishes

    Aiden.C - MSFT |Microsoft Community Support Specialist

    2 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2024-11-08T08:36:11+00:00

    Hi,

    try this

    Sub Delete_LARGE_Define_Names()

    '## 08-11-2024 ##

    Dim wb

    Set wb = ThisWorkbook

    Dim df As Name

    Dim N As Long, Limit As Long, m As Long

    Limit = 10000 '<< delete 10000 entries

    N = wb.Names.Count

    MsgBox "total df names=" & N

    If N = 0 Then Exit Sub

    Select Case N

    Case N <= Limit

    For Each df In wb.Names

    df.Delete

    Next df

    Case Else

    m = 0

    For Each df In wb.Names

    m = m + 1

    df.Delete

    If m > Limit Then

    MsgBox "del. df names = " & Limit & vbLf & "current df names =" & N - Limit

    Exit Sub

    End If

    Next df

    End Select

    End Sub

    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Anonymous
    2024-11-05T20:57:57+00:00

    is there a version of this that only deletes the first 10,000 names or so? I run out of memory when I try to delete all the names at once.

    Thanks

    0 comments No comments
  5. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more