Document Editing Problems

Insert Word Table Rows Below the Cursor with VBA

Rana GarciaRana Garcia Nov 22, 2026 868 views

Question details

Modify a Word VBA macro to insert a table row below the row containing the cursor.

Insert Word Table Rows Below the Cursor with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A user is editing a Word table and wants a macro to add a row below the current cursor position.
Observed behavior
The macro should insert a new row below the current row, including when the cursor is in the last row.
Before you start

Open the document in Microsoft Word and place the cursor inside the table row where you want to insert a row below. Make sure you can access the VBA editor and that macros are permitted for the document.

Solution 1Recommended

Update the Word VBA macro to insert below the current row

Use the next row as the insertion reference, or append a row when the cursor is in the last row.

1
Open the VBA editor

In Word, open the VBA editor with Alt+F11, then open the module containing your table-row macro.

2
Update the insertion code

Replace the relevant insertion logic with this example: Sub InsertRowBelowCursor() Dim oTbl As Table Dim lngPosit As Long If Not Selection.Information(wdWithInTable) Then MsgBox "Place the cursor inside a table first." Exit Sub End If Set oTbl = Selection.Tables(1) lngPosit = Selection.Rows(1).Index If lngPosit < oTbl.Rows.Count Then oTbl.Rows.Add BeforeRow:=oTbl.Rows(lngPosit + 1) Else oTbl.Rows.Add End If End Sub

3
Run the macro

Return to the document, click inside a table row, and run InsertRowBelowCursor from the Macros dialog. Test both a middle row and the last row.

If error 5941 appears: The requested collection member may not exist. Confirm that the cursor is inside a table and that the next-row index is within the table; the last row has no next row to use as a reference. Tables with merged cells can also complicate row indexing.
Free Microsoft Office alternative

Edit Word tables with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for editing documents and tables. Its Word format compatibility makes moving documents from Microsoft Office straightforward, although it does not fix Microsoft Word VBA errors.

Edit document tables in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface for everyday document editingWork with a lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro use the next row as a reference?

Word's Rows.Add method inserts before the specified BeforeRow. Referencing oTbl.Rows(lngPosit + 1) therefore places the new row below the current row.

How do I insert below the last row?

When the current row is the last row, call oTbl.Rows.Add without a BeforeRow argument. This appends a row to the table.

What should I check if I get runtime error 5941?

Click inside the intended table before running the macro and check that the requested table or row exists. In particular, don't reference lngPosit + 1 when the current row is the last row.

Can I add a row without using a macro?

In Word, click inside the table row, then use the table layout tools and select Insert Below.