How to Use Extract Formula Command in Excel
In this article
The Extract Formula command in Excel is not a built-in ribbon button; it is a custom VBA macro you add to your workbook to list every formula on a sheet along with its cell address. To use it, open the VBA editor with Alt+F11, insert a new module, paste a short macro that loops through the UsedRange and writes each cell's .Formula property to a new sheet, then run it with Alt+F8. The result is a clean inventory of formulas you can audit, document, or migrate. This guide walks through creating and running that macro safely, plus what to do when it fails.
What You'll Need
- Excel for Windows or Mac (the steps below use the desktop app; the web version cannot run VBA macros).
- A workbook saved as .xlsm (macro-enabled) or .xlsb before you add code, so the macro persists.
- Macro security set to allow macros in trusted locations, or the ability to enable macros when prompted.
- Basic familiarity with the VBA editor (Alt+F11 opens it).
Note: menu labels and dialog wording can differ slightly by Excel version, platform, and region. The keyboard shortcuts and VBA objects used here are stable across current desktop versions.
Step-by-Step
- Save a copy of your workbook first. Macros write to your file; keep an untouched backup so you can compare results or recover if something goes wrong.
- Save the file as macro-enabled. Go to File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). If you skip this, Excel will warn you on close that macros will be lost.
- Open the VBA editor. Press Alt+F11 (on Mac, Fn+Alt+F11 or the Developer tab > Visual Basic). If the Developer tab is hidden, enable it via File > Options > Customize Ribbon and tick Developer.
- Insert a module. In the VBA editor, right-click your workbook name in the Project pane and choose Insert > Module. A blank code window opens.
- Paste the extract macro. Use this code, which creates a new sheet named "FormulaList" and writes the address, formula, and value of every formula cell on the active sheet:
Sub ExtractFormulas() Dim ws As Worksheet, out As Worksheet Dim c As Range, r As Long Set ws = ActiveSheet On Error Resume Next Set out = ThisWorkbook.Sheets("FormulaList") On Error GoTo 0 If out Is Nothing Then Set out = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) out.Name = "FormulaList" Else out.Cells.Clear End If out.Range("A1:D1").Value = Array("Cell", "Formula", "Value", "Sheet") r = 2 For Each c In ws.UsedRange If c.HasFormula Then out.Cells(r, 1).Value = c.Address(False, False) out.Cells(r, 2).Value = c.Formula out.Cells(r, 3).Value = c.Value out.Cells(r, 4).Value = ws.Name r = r + 1 End If Next c out.Columns("A:D").AutoFit MsgBox "Extracted " & (r - 2) & " formulas.", vbInformation End Sub - Close the editor and select the sheet to audit. The macro works on the active sheet, so click the tab containing the formulas you want to extract.
- Run the macro. Press Alt+F8, select ExtractFormulas, and click Run. A message box reports how many formulas were found.
- Review the FormulaList sheet. Column A shows the cell address, B the formula text, C the calculated value, and D the source sheet name. Filter or sort as needed.
- Repeat for other sheets. Because the macro clears and rewrites FormulaList each run, either copy the results to a new sheet between runs or modify the code to append rows instead of clearing.
- Save and, if you like, remove the macro. Save the .xlsm file. If you only needed a one-time audit, you can delete the module (right-click it in the VBA editor > Remove) and save as .xlsx to strip the macro.
Common Mistakes
- Running it on the wrong sheet. The macro uses
ActiveSheet; if FormulaList is active, it will find no formulas. Always click the source sheet first. - Saving as .xlsx. Excel silently drops the macro. Use .xlsm.
- Forgetting that
.Formulareturns formulas in the user's language. If your Excel is set to a non-English locale, function names may appear translated; use.FormulaLocalonly if you need that, or.Formulafor the canonical English form. - Assuming it captures every cell. The macro loops over
UsedRange, which can miss cells outside the used range or include stale formatting far from your data. Select the exact range and loop overSelectioninstead if precision matters. - Leaving macros enabled in files from unknown sources. Only run code you wrote or verified; macro security exists for a reason.
Tips
- To extract formulas from a specific range rather than the whole sheet, replace
ws.UsedRangewithSelectionand select the range before running. - Add a column for
c.NumberFormatif you need to document formatting alongside formulas. - Use
c.HasArrayto flag array formulas separately, since they behave differently when copied. - If you plan to share the workbook, note that recipients must enable macros or the button/macro will not run.
- Keep a version of the workbook without macros for distribution; .xlsm files trigger security warnings in email.
Troubleshooting
The macro does nothing or shows zero formulas. Confirm you are on the correct sheet and that the cells actually contain formulas (a value typed as text is not a formula). Check that the sheet is not protected; protected sheets can still be read, but if the macro tries to write to a protected output sheet it will fail.
You get a "Macros are disabled" message. Close the file, then reopen and click Enable Content in the yellow bar. If your organisation blocks macros, you may need to use a trusted location or ask IT; there is no safe way to bypass a deliberate policy.
"Subscript out of range" error. This usually means the sheet name in the code does not match. The macro creates FormulaList if missing, but if a sheet with a similar name exists, rename or adjust the code.
The output is incomplete. UsedRange may not cover everything. Select the full range and change the loop to iterate over Selection. Also check for hidden rows or columns, which are included but easy to overlook.
Formulas appear as text with an apostrophe. The cell likely contains text, not a formula. Remove the leading apostrophe or re-enter the formula.
Nothing works after an Excel update. VBA remains supported in desktop Excel, but the web app cannot run macros. Open the file in the desktop app.
Frequently Asked Questions
Is there a built-in "Extract Formula" command in Excel?
No. Excel has Show Formulas (Ctrl+`) to display formulas in place, and FORMULATEXT to return a formula as text in a cell, but neither produces a list of every formula with its address. The extract workflow described here is a custom VBA macro.
Can I use FORMULATEXT instead of a macro?
Yes, for a single cell. Enter =FORMULATEXT(A1) to show A1's formula as text. To list many formulas, you would still need to fill that down and handle errors where cells contain no formula; a macro automates the whole sheet.
Does this work in Excel for the web or on mobile?
No. Excel for the web and the mobile apps do not run VBA macros. Use the desktop version on Windows or Mac.
Will the macro change my original formulas?
No. It only reads each cell's formula and writes a copy to a new sheet. Your source cells are untouched, but always keep a backup before running any macro.
Can I extract formulas from multiple sheets at once?
Not with the basic macro above, which handles the active sheet. You can loop over ThisWorkbook.Worksheets and append results, but adjust the code carefully and test on a copy first.
Why do some formulas show as values in the output?
The macro writes c.Formula, which should be the formula text. If a cell contains a hard-coded value, it has no formula and is skipped. If a formula cell shows a value, check whether the cell is part of an array or data table, which may need different handling.