Access Calculated Column Formulas in an Empty Excel Table
Question details
Retrieve a calculated column formula from an Excel table after all of its data rows have been deleted.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA macro needs to access a ListObject calculated column formula while the table has no data rows.
- Observed behavior
- ListColumn.DataBodyRange does not expose the formula when the table has no data rows, although Excel may still populate the formula when a new row is added.
Identify the table and column names in Excel, and confirm that the table has no data rows. If you use the temporary-row method, make sure adding a row will not disrupt adjacent worksheet content.
Add a Temporary Table Row and Read Its Formula with VBA
Use this workaround when Excel still automatically fills the calculated column in a new row.
When a table has no data rows, its DataBodyRange is Nothing. The Excel Object Model does not directly expose the retained calculated column formula in that state.
The following example is intended only for an empty table. It adds one row, reads the formula if Excel fills it, and removes the temporary row.
In Excel, press Alt+F11, then choose Insert > Module. Replace Sheet1, Table1, and Amount in the example with your worksheet, table, and column names.
Paste the following code into the module and run ReadEmptyTableFormula: Sub ReadEmptyTableFormula() Dim tbl As ListObject Dim tempRow As ListRow Dim colIndex As Long Dim formulaText As String On Error GoTo CleanUp Set tbl = ThisWorkbook.Worksheets("Sheet1").ListObjects("Table1") If tbl.ListRows.Count <> 0 Then MsgBox "The table is not empty." Exit Sub End If colIndex = tbl.ListColumns("Amount").Index Set tempRow = tbl.ListRows.Add If tempRow.Range.Cells(1, colIndex).HasFormula Then formulaText = tempRow.Range.Cells(1, colIndex).Formula Else formulaText = "No formula was populated." End If tempRow.Delete Set tempRow = Nothing MsgBox formulaText Exit Sub CleanUp: On Error Resume Next If Not tempRow Is Nothing Then tempRow.Delete MsgBox "Could not read the formula. Check the table and column names." End Sub
Read the message box for the formula. If it says no formula was populated, check Excel's calculated-column autofill settings or inspect the workbook's Open XML instead.

Inspect the Table's Calculated Column Formula in Open XML
Use this method when you need to inspect the saved workbook structure without adding a table row.
Work with Excel-Compatible Tables in WPS Office
WPS Office is a free, lightweight alternative for everyday spreadsheet work. Its familiar interface and Excel format compatibility make it easy to move existing workbooks into WPS Spreadsheets. It does not resolve Excel's Object Model limitation.

Frequently Asked Questions
Why can't VBA read DataBodyRange.Formula from an empty table?
With no data rows, the table's DataBodyRange is Nothing, so there are no body cells from which to read a formula. Add a temporary ListRow if Excel will populate it, or inspect the saved table XML.
What if Excel doesn't fill the formula in the temporary row?
Check Excel's calculated-column autofill settings and whether the table still retains the formula. If no formula appears in the new row, look for calculatedColumnFormula in the saved workbook's xl/tables XML files.
Where is the calculated column formula stored in an Excel workbook?
In an .xlsx or .xlsm package, a table definition under xl/tables may contain a calculatedColumnFormula element inside the relevant tableColumn element. The element is not guaranteed to be present.
Can I use the Open XML method with an .xlsb workbook?
No. An .xlsb workbook uses a binary format rather than the Open XML table files described here. Use the temporary-row method if Excel fills the calculated column.




