VBA & Macro Problems

Access Calculated Column Formulas in an Empty Excel Table

Maira MehtabMaira Mehtab Nov 18, 2026 869 views

Question details

Retrieve a calculated column formula from an Excel table after all of its data rows have been deleted.

Access Calculated Column Formulas in an Empty Excel Table
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11, then choose Insert > Module. Replace Sheet1, Table1, and Amount in the example with your worksheet, table, and column names.

2
Add and run the macro

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

3
Check the result

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.

Add a Temporary Table Row and Read Its Formula with VBA
Autofill is required: This method works only if Excel fills the new row with the retained formula. The temporary row may also trigger worksheet events.
Free Microsoft Office alternative

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.

Open and edit spreadsheet tables and formulas in a familiar interfaceCompatible with Microsoft Excel .xlsx and .xls filesMove existing Excel workbooks into WPS for everyday editingFree and lightweight for common office tasks
QA img-9

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.