Excel VBA: Add a Row to the Bottom of a Table
In this article
To add a row to the bottom of an Excel table with VBA, use the ListObject object's ListRows.Add method with no arguments, or set ListRows.Add(AlwaysInsert:=True) to force a new row even when the table is empty. The correct target is the table's Range, not the worksheet's last used row, because the table expands automatically and any formulas, formats, and data validation carry down. The steps below show the reliable pattern, plus how to write values into the new row and avoid the common mistakes that leave data outside the table.
What You'll Need
- Excel with macros enabled (the Developer tab visible, or the ability to open the VBA editor with Alt+F11).
- A worksheet containing a real Excel table (created with Insert > Table, not just formatted cells). The table needs a name; the default is Table1, Table2, and so on, visible in Table Design > Table Name.
- A macro-enabled workbook (.xlsm) if you want to keep the code.
- Basic familiarity with the VBA editor: inserting a module and pressing F5 to run.
Menu labels in Excel can differ slightly by version, platform, and region, so if a name does not match exactly, look for the closest equivalent.
Step-by-Step
- Confirm the range is a real table. Click any cell inside the data. If the Table Design tab appears on the ribbon, it is a table. If not, select the range and use Insert > Table, making sure "My table has headers" is ticked. A plain formatted range will not expand automatically, which is the root of most problems later.
- Note the table name. With a cell selected, read the name in Table Design > Table Name (for example, Table1). You can rename it there to something meaningful like SalesData. The name must be used exactly in code, with no spaces unless you handle them carefully.
- Open the VBA editor. Press Alt+F11 (on Mac, Fn+Alt+F11 or the Developer tab). In the Project pane, right-click your workbook, choose Insert > Module. A blank code window appears.
- Write the basic procedure. Type a Sub that references the table by name and calls ListRows.Add:
Replace Sheet1 and Table1 with your actual sheet and table names.Sub AddRowToTable() Dim tbl As ListObject Set tbl = ThisWorkbook.Worksheets("Sheet1").ListObjects("Table1") tbl.ListRows.Add End SubListRows.Addwith no arguments appends a row at the bottom of the table and returns the new ListRow object. - Run it. Place the cursor inside the Sub and press F5, or use Run > Run Sub/UserForm. A blank row appears at the bottom of the table, and the table's range grows by one row. Any formulas in the table columns fill down automatically, and formats and data validation extend to the new row.
- Write values into the new row. Capture the returned object so you can populate it:
Dim newRow As ListRow Set newRow = tbl.ListRows.Add newRow.Range(1, 1).Value = Date newRow.Range(1, 2).Value = "New entry" newRow.Range(1, 3).Value = 100newRow.Range(1, columnNumber)addresses cells within that row only, so column positions stay relative to the table even if the table moves on the sheet. - Handle an empty table. If the table has headers but no data rows,
ListRows.Addcan behave unexpectedly depending on how the table was created. Usetbl.ListRows.Add(AlwaysInsert:=True)to force insertion. This is the safe default for tables that may be cleared and refilled. - Add several rows in a loop. Call
ListRows.Addonce per row inside a For loop. Do not try to resize the table range manually; let the ListObject manage its own size. If you need speed with many rows, write to an array and assign it in one operation to the new rows' ranges, but keep the row creation through ListRows.Add. - Save the workbook as .xlsm. Use File > Save As and choose Excel Macro-Enabled Workbook. A normal .xlsx save discards the code.
Common Mistakes
- Using
Cells(Rows.Count, 1).End(xlUp).Offset(1)instead of the table object. That finds the last used row of the whole worksheet, which may be far below the table or in a different block of data, so the new entry lands outside the table and does not inherit formulas or formats. - Referencing the sheet by index.
Worksheets(1)breaks silently if sheets are reordered. Use the sheet name or a worksheet codename. - Hard-coding the table name incorrectly. Table names cannot contain spaces, and the name in code must match exactly, including case-insensitive spelling. A mismatch raises "Subscript out of range" at runtime.
- Assuming the table starts at row 1. Code that writes to fixed cell addresses like A10 will miss the table if it has moved. Always go through
newRow.Range. - Forgetting that formulas may already fill the row. If a column has a calculated formula, writing a value into it overwrites the formula for that row only. Write only to input columns.
- Running the macro while the sheet is protected. Insertion fails. Unprotect the sheet in code or before running, and re-protect afterwards if needed.
Tips
- Use
ThisWorkbookrather thanActiveWorkbookso the macro always targets the workbook that contains it, regardless of what is open. - Give tables meaningful names in Table Design > Table Name. Code that reads
ListObjects("SalesData")is far easier to maintain thanListObjects("Table7"). - If the table is the only one on the sheet,
Worksheets("Sheet1").ListObjects(1)works, but named access is safer. - Turn off
Application.ScreenUpdatingat the start and back on at the end when adding many rows; this speeds up the macro noticeably. - To add a row above a specific existing row rather than at the bottom, pass a position:
tbl.ListRows.Add(Position:=2)inserts before the second data row. With no argument, the row goes to the bottom. - Remember that the table's header row is not a ListRow;
ListRows.Countcounts data rows only.
Troubleshooting
"Subscript out of range" when the macro runs. The sheet name or table name in the code does not match the workbook. Check both in the Name Box and Table Design tab, and confirm the workbook is the one the code expects.
The new row appears outside the table. The code is almost certainly using worksheet-level cell references rather than the ListObject. Replace those lines with tbl.ListRows.Add and newRow.Range.
Formulas do not fill into the new row. The column may not have a consistent formula in every existing row. Excel's calculated-column behaviour depends on the formula being present throughout the column; re-enter it in the whole column and try again.
The macro does nothing at all. Macros may be disabled, or the code may be in a standard module but not actually invoked. Check the Trust Center macro settings, confirm the Sub name, and run it from the Macros dialog (Developer > Macros) to see any error message.
"Method 'Add' of object 'ListRows' failed." The sheet is often protected, or the workbook is shared in a mode that blocks structural changes. Unprotect the sheet and unshare the workbook, then retry.
The row is added but values land in the wrong columns. Column numbering in newRow.Range(1, n) is relative to the table's first column, not the worksheet's column A. Count from the table's left edge.
Frequently Asked Questions
Does ListRows.Add copy formulas and formats to the new row?
Yes, in a normal table it extends the calculated columns, cell formats, and data validation from the row above. If a column lacks a consistent formula, that column may not fill automatically.
Can I add a row to a table on a different sheet?
Yes. Qualify the ListObject with the correct worksheet, for example ThisWorkbook.Worksheets("Data").ListObjects("Table1").ListRows.Add.
What is the difference between ListRows.Add and adding a row with EntireRow.Insert?
EntireRow.Insert shifts worksheet rows and does not reliably extend the table. ListRows.Add is the table-aware method and keeps the table's range, formulas, and formatting intact.
Can I add a row at the top of the table instead of the bottom?
Yes, pass a position: tbl.ListRows.Add(Position:=1) inserts a new first data row. Omitting the argument appends at the bottom.
Why does the macro fail when the table has no data rows?
Some table structures need an explicit insert. Use tbl.ListRows.Add(AlwaysInsert:=True) to force the row into an empty table.
Will this work in Excel for Mac?
The ListObject object and ListRows.Add method are part of the cross-platform object model, so the same code runs in Excel for Mac. The VBA editor is opened differently, and some ribbon labels vary, but the method itself is the same.