Sub topic 13
Converting a table back to a range
This chapter assumes you can create a table, name it, and read structured references such as SalesTable[Amount]. It also assumes you know the Table Design tab on the Ribbon. Converting a table back to a plain range is a one-way change for a few features, so it helps to know what you give up first.
Why convert at all
A table is the better container for most lists. Sometimes it gets in the way, and these are the usual reasons to convert:
- You need a feature that Excel disables inside tables. The Subtotal command on the Data tab is the common example.
- You want fixed cell references instead of structured references, for example to match a template or an older workbook that other people maintain.
- You do not want the table to grow automatically, or you do not want Excel to fill formulas down by itself.
- You inherited a table that was created by accident and you want the sheet back to a plain grid.
Consider a smaller fix before you convert. If the only annoyance is automatic formula fill, you can switch off that option in the AutoCorrect settings and keep the table.
What conversion does
Conversion removes the table object (the ListObject) and leaves the cells alone. Your values stay, and the formatting stays as well.
Some things change as a result:
| Feature | After conversion |
|---|---|
| Cell values | Unchanged |
| Table style (banding, header colours) | Kept as ordinary cell formatting that no longer follows the data |
| Table name | Removed |
| Filter buttons | Removed |
| Slicers | Removed from the table, so they stop filtering |
| Structured references | Rewritten as normal cell references |
| Calculated columns | Each cell keeps its formula, but Excel no longer fills new rows |
| Total row | Stays as an ordinary row of formulas |
| Automatic expansion | Stops |
The formatting point matters most in practice. The banded rows you saw before are now fixed to specific cells. If you sort the range afterwards, the colours do not move with the data, and they do not extend to new rows.
How formulas are rewritten
Excel rewrites structured references so that the formulas keep working. Take the formulas from earlier chapters. Suppose the table sits in A1:D7, with Quantity in B, Unit Price in C and Amount in D.
A calculated column formula in row 2 looks like this in the table:
=[@Quantity]*[@[Unit Price]]After conversion, the same cell holds a normal reference formula:
=B2*C2A formula elsewhere that summed the whole column looked like this:
=SUM(SalesTable[Amount])It now points at the fixed block of cells. Excel may write it with dollar signs.
=SUM(D2:D7)The same happens to the total row formula:
=SUBTOTAL(109,SalesTable[Amount])This becomes:
=SUBTOTAL(109,D2:D7)These fixed references are the cost of converting. The formula SUM(D2:D7) will not include a row you type into row 8, whereas the structured reference would have.
Other objects that point at the table
Charts, PivotTables and named ranges can use a table as their source. Conversion rewrites these sources to fixed addresses, and the objects keep working. They lose the ability to grow with the data. A chart that updated when you added rows will silently stop including new rows. After converting, check each object that was fed by the table, and fix the source range by hand where you want it to cover more cells.
Converting with the Ribbon
- Click any cell inside the table.
- On the Table Design tab, in the Tools group, choose Convert to Range.
- Excel asks "Do you want to convert the table to a normal range?" Choose Yes.
You can get the same command by right-clicking a cell in the table, choosing Table, and then Convert to Range.
If the command is missing, the active cell is not inside a table, or the sheet is protected. Protected sheets block the command until you unprotect them.
Undoing the conversion
If you notice a mistake straight away, press Ctrl+Z. Undo restores the table with its name and slicers. Once you have made other changes, undo can no longer help. If you need the table back later, you must select the range and create a new table. The new table starts with a default name such as Table1, so you also have to rename it and recreate any slicers.
Preparing before you convert
A few checks before you convert will save you rework.
- Clear filters. The filter buttons disappear on conversion, and rows hidden by a filter can stay hidden. Choose Clear on the Data tab first, so that you can see all your rows.
- Note the table name. Formulas in other sheets and other workbooks that mention
SalesTable[...]are converted, but external workbooks that refer to the table by name may not update. Search your workbooks for the name first. - Decide about the style. If you want the plain look back, set the style to None before you convert. After conversion, the colours are ordinary cell fill and you would have to clear them by hand.
- Look at objects that depend on the table. List the charts, PivotTables and slicers that use it.
Converting with VBA
The ListObject object has an Unlist method, which does what the Convert to Range command does. This is the short version from the spine:
Sub ConvertSalesTableToRange()
ActiveSheet.ListObjects("SalesTable").Unlist
End SubIt fails with a run-time error if the sheet has no table of that name. It also fails on a protected sheet. A safer version checks for the table, clears filters and removes the style first:
Sub ConvertSalesTableSafely()
Dim tbl As ListObject
On Error Resume Next
Set tbl = ActiveSheet.ListObjects("SalesTable")
On Error GoTo 0
If tbl Is Nothing Then
MsgBox "SalesTable was not found on this sheet."
Exit Sub
End If
If tbl.ShowAutoFilter Then
If tbl.AutoFilter.FilterMode Then tbl.AutoFilter.ShowAllData
End If
tbl.TableStyle = ""
tbl.Unlist
End SubSetting TableStyle to an empty string removes the style, so the cells are left without table formatting. Leave that line out if you want to keep the look.
Unlike the Ribbon command, Unlist cannot be undone with Ctrl+Z. Running a macro clears Excel's undo history, so save a copy of the workbook before you run it on important data.
To see which tables exist before you convert, you can list them all:
Sub ListTablesOnSheet()
Dim tbl As ListObject
For Each tbl In ActiveSheet.ListObjects
Debug.Print tbl.Name & " covers " & tbl.Range.Address
Next tbl
End SubCommon errors and edge cases
- The Convert to Range button is greyed out. Check that a cell inside the table is selected, and that the sheet is not protected. A table linked to a SharePoint list can need more steps, since it must be unlinked first.
- Formulas still show structured references after conversion. This usually means the formula lives in a different workbook, or a defined name contains the reference. Edit those by hand.
- Colours look wrong after sorting. Banding is now fixed formatting. Clear the fills and apply a new style, or turn the range back into a table.
- Hidden rows remain. A filter was active during conversion. Select the rows around the hidden ones and use Unhide, or reapply the Clear command.
- A chart stops showing new rows. The chart source became a fixed address. Edit the series ranges, or convert the data back into a table.
Exercise
You convert SalesTable to a range. A cell that held =[@Quantity][@[Unit Price]] now shows =B5C5. Two weeks later you type a new row directly below the old data. What happens to the formula in the new row, and what happens to =SUM(D2:D7), which used to read =SUM(SalesTable[Amount])?
Show answer
The new row gets no formula automatically, because the range no longer fills calculated columns, so you must copy the formula down yourself. The SUM stays at D2:D7 and ignores the new row. You must extend it by hand, or turn the range back into a table so the references grow again.
Exercise
A macro runs ActiveSheet.ListObjects("SalesTable").Unlist and then stops with a run-time error on a worksheet that has been protected. Give two ways to prevent that error.
Show answer
Unprotect the sheet before calling Unlist and protect it again afterwards. Or check beforehand with the sheet's ProtectContents property and exit with a message. Also confirm the table name exists first, because a missing name raises a different error.