To list all named ranges in an Excel workbook using VBA, you can run a simple macro that scans the workbook’s ThisWorkbook.Names collection and outputs each name, scope, and referring address to a new worksheet. This helps audit, document, or debug named ranges across large or complex spreadsheets. No special add-ins or external tools are required—just Excel with VBA enabled and basic familiarity with the Visual Basic Editor.

What You'll Need

  • Microsoft Excel (2010 or later recommended)
  • VBA enabled in Excel (macro settings must allow code execution)
  • Basic understanding of the Visual Basic Editor (VBE)
  • A workbook with at least one named range (optional, but you’ll see the list even if empty)

Step-by-Step

  1. Open the Excel workbook where you want to list named ranges.
  2. Press Alt + F11 to open the Visual Basic Editor (VBE).
  3. In the VBE, go to Insert > Module to create a new standard module. This opens a blank code window.
  4. Copy and paste the following VBA code into the module window:
    Sub ListAllNamedRanges()
        Dim ws As Worksheet
        Dim nm As Name
        Dim i As Long
        
        ' Create a new worksheet for the output
        Set ws = ThisWorkbook.Worksheets.Add
        ws.Name = "NamedRanges_List"
        
        ' Set up headers
        ws.Range("A1").Value = "Name"
        ws.Range("B1").Value = "Scope"
        ws.Range("C1").Value = "Refers To"
        ws.Range("D1").Value = "Comment"
        ws.Range("A1:D1").Font.Bold = True
        
        i = 2
        
        ' Loop through all names in the workbook
        For Each nm In ThisWorkbook.Names
            ws.Cells(i, 1).Value = nm.Name
            ' Determine scope: Workbook-level or Worksheet-level
            If nm.Parent Is ThisWorkbook Then
                ws.Cells(i, 2).Value = "Workbook"
            Else
                ws.Cells(i, 2).Value = "Worksheet: " & nm.Parent.Name
            End If
            ws.Cells(i, 3).Value = nm.RefersTo
            ws.Cells(i, 4).Value = nm.Comment
            i = i + 1
        Next nm
        
        ' Auto-fit columns for readability
        ws.Columns("A:D").AutoFit
        
        ' Activate the new sheet for immediate review
        ws.Activate
        
        MsgBox "List of named ranges created on sheet '" & ws.Name & "'. Total found: " & (i - 1), vbInformation
    End Sub
  5. Close the VBE by clicking the X in the top-right corner or pressing Alt + Q.
  6. Ensure the workbook is saved as a macro-enabled file (.xlsm). Go to File > Save As > Browse, then select Excel Macro-Enabled Workbook (*.xlsm) from the "Save as type" dropdown.
  7. Press Alt + F8 to open the Macro dialog, select ListAllNamedRanges, and click Run.
  8. A new worksheet named NamedRanges_List will appear, populated with all defined names, their scope (Workbook or Worksheet), the RefersTo formula (e.g., =Sheet1!$A$1:$B$10), and any comment attached to the name.

Common Mistakes

  • Running the macro in a .xlsx file: If the workbook is saved as standard .xlsx, macros are disabled and the code won’t execute. Always save as .xlsm first.
  • Ignoring macro security settings: If Excel blocks macros, the macro won’t run. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros (temporarily, for testing only—revert after).
  • Overwriting existing sheets: The code creates a *new* sheet named NamedRanges_List. If that sheet already exists, the macro will throw a runtime error. Delete it first or modify the code to handle duplicates (e.g., rename to NamedRanges_List_2).
  • Using Application.Names instead of ThisWorkbook.Names: Application.Names includes names from *all* open workbooks, which may include add-ins or unrelated files—leading to irrelevant entries. Always use ThisWorkbook.Names to target only the active workbook.

Tips

  • Filter the list: After running the macro, apply Excel’s Filter (Data > Filter) to the headers. You can then filter by scope (e.g., show only "Workbook" names) or by cell range patterns (e.g., find all names referencing $A$).
  • Export to CSV: Once listed, copy the table and paste as values into a new workbook, then save as CSV for sharing or archiving without macros.
  • Check hidden names: Some names (e.g., _FilterDatabase, Print_Area) are system-defined and hidden in the Name Manager. This macro lists *all* names—including hidden ones—so you’ll see even those not visible in the UI.
  • Add error handling: For large workbooks, add On Error Resume Next before the loop and On Error GoTo 0 after to skip corrupt or broken name references without crashing the macro.
  • Include worksheet name in scope: If a name is worksheet-scoped, the comment in the "Scope" column will show Worksheet: Sheet1. This is critical for troubleshooting because two workbooks can have identically named ranges on different sheets, causing confusion.

Troubleshooting

If the macro fails or produces unexpected results, follow these steps:

  1. Check for #NAME? errors: In the "Refers To" column, if you see #NAME?, the name refers to a deleted sheet or invalid cell reference. Go to Formulas > Name Manager, find the problematic name, and delete or correct it.
  2. Runtime error 1004 (Application-defined or object-defined error): This usually occurs if a name’s RefersTo property is malformed. Temporarily wrap the loop in error-handling:
    For Each nm In ThisWorkbook.Names
        On Error Resume Next
        ws.Cells(i, 3).Value = nm.RefersTo
        On Error GoTo 0
        i = i + 1
    Next nm
  3. Sheet creation fails: If Excel blocks creating a new sheet (e.g., due to protection), unprotect the workbook first: Review > Unprotect Workbook (enter password if set).
  4. No names appear: Confirm names exist by opening Formulas > Name Manager. If the list is empty, the workbook genuinely has no defined names. Note: Excel’s automatic features (like tables) create implicit named ranges (e.g., Table1[#All]), but these won’t show in ThisWorkbook.Names—only explicit names created via Name Manager or VBA will.
  5. Macro not listed in Alt+F8: Ensure you pasted the code into a *standard module* (not ThisWorkbook or a sheet’s code pane). Also, verify macro security isn’t blocking execution (see Common Mistakes).

Frequently Asked Questions

Does this include names from linked workbooks?

No. ThisWorkbook.Names only lists names defined in the *current* workbook. External references (e.g., =[SalesData.xlsx]Sheet1!$A$1) are included in the "Refers To" column only if the name itself is defined locally—but the external file must be open for the link to resolve, and broken links may show as #[SalesData.xlsx]Sheet1!$A$1 with a red error indicator.

Can I list only worksheet-scoped names?

Yes. Modify the loop condition:
For Each nm In ThisWorkbook.Names
    If Not nm.Parent Is ThisWorkbook Then ' Worksheet-scoped only
        ' ... process entry ...
    End If
Next nm

Why does one name show as xlFilterDatabase or _FilterDatabase?

These are internal Excel names created for AutoFilter drop-downs. They’re hidden in Name Manager by default but visible to VBA. They’re harmless—ignore or delete them only if you’re cleaning up unused names.

Does this work in Excel Online or mobile?

No. VBA macros are only supported in desktop Excel (Windows/macOS). Excel Online and mobile apps cannot run or edit VBA code. Use Name Manager in the desktop app to review names, then sync via OneDrive/SharePoint.

How do I delete unused named ranges after reviewing?

After listing them, you can manually delete via Formulas > Name Manager, or extend the macro: add a column for "Delete?" (Y/N), then loop through rows marked "Y" and run ThisWorkbook.Names(nm.Name).Delete. Be cautious—deleting a name used in formulas will break those formulas.

Can I export the list to a text file instead of a worksheet?

Yes. Replace the worksheet output with a text file using the FileSystemObject:
Dim fso As Object, ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("C:\NamedRanges.txt", True)
For Each nm In ThisWorkbook.Names
    ts.WriteLine nm.Name & vbTab & nm.RefersTo
Next nm
ts.Close
Adjust the path and add headers as needed. Ensure the folder exists and Excel has write permissions.