How to Delete All Table Rows Below Cursor with a Word VBA Macro
Question details
The user needs a Word VBA macro script that identifies the cursor's current position within a table and deletes every row beneath it, rather than just deleting a single subsequent row.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Editing a document containing large tables where multiple trailing rows below a specific entry need to be removed automatically and quickly.
- Observed behavior
- The user's current VBA macro only deletes the immediately following row, leaving the rest of the rows beneath the cursor intact.
Ensure your document is saved as a Macro-Enabled Document (.docm). Always test VBA scripts on a backup copy of your file, as running a macro typically clears your undo history.
Use a VBA Loop to Delete All Rows Below the Cursor
Implement a VBA macro that counts the total rows in the active table and uses a backward loop to delete everything below your current cursor position.
To delete multiple rows instead of just one, the macro must determine the total number of rows in the table and the row index of the cursor. By looping backwards from the bottom of the table up to the row immediately below the cursor, the macro safely removes all subsequent rows without throwing index errors.
Open your document in Microsoft Word. Press 'Alt + F11' on your keyboard to launch the Microsoft Visual Basic for Applications (VBA) editor.
In the left-hand Project Explorer pane, right-click on your document name, select 'Insert', and then click 'Module'. This will create a blank space for your code.
Copy and paste the following code into the module window: Sub DeleteRowsBelow() Dim tbl As Table Dim currentRow As Integer Dim totalRows As Integer Dim i As Integer If Selection.Information(wdWithInTable) Then Set tbl = Selection.Tables(1) currentRow = Selection.Cells(1).RowIndex totalRows = tbl.Rows.Count For i = totalRows To currentRow + 1 Step -1 tbl.Rows(i).Delete Next i End If End Sub
Close the VBA editor. Place your cursor in the table row you wish to keep. Press 'Alt + F8', select 'DeleteRowsBelow' from the macro list, and click 'Run'.

Manage Document Tables Efficiently with WPS Writer
WPS Office Writer offers an intuitive interface with robust built-in table management tools, reducing the need for complex VBA coding. For advanced users, the professional version of WPS Office fully supports VBA macros, ensuring your existing scripts run flawlessly.
- 1. Download and Install: Download WPS Office Free from the official website and install it on your computer.
- 2. Open Your Document: Launch WPS Writer and open your Word document. Your tables and formatting will remain perfectly intact.
- 3. Use Built-in Table Tools: Click inside your table. Use the 'Table Tools' tab that appears on the ribbon to quickly select and delete multiple rows with just a few clicks, bypassing the need for macros entirely.
- 4. Run Macros (Pro Version): If you prefer using VBA, navigate to the 'Developer' tab, click 'Macros', and execute your custom scripts exactly as you would in Microsoft Word.

Frequently Asked Questions
Why does my original macro only delete one row instead of all of them?
Your original macro used a simple 'If' statement to target the row immediately below the cursor (RowIndex + 1) and executed the 'Delete' command once. To delete all remaining rows, the code requires a loop (like a 'For...Next' statement) to repeat the deletion process until the end of the table is reached.
How do I enable macros in Word to run this code?
To run macros, you must first enable the Developer tab by going to File > Options > Customize Ribbon and checking 'Developer'. Then, navigate to the Developer tab, click 'Macro Security', and choose 'Enable all macros' (or enable them on a case-by-case basis when prompted). Finally, save your file as a Macro-Enabled Document (.docm).
Can I undo a macro after it deletes the table rows?
Usually, running a VBA macro clears the document's undo history, meaning you cannot simply press 'Ctrl + Z' to retrieve the deleted rows. It is highly recommended to manually save your document or work on a duplicate copy before executing any table-altering macros.
Will this macro delete rows in every table across my document?
No. The macro specifically targets 'Selection.Tables(1)', which refers exclusively to the single table where your text cursor is currently active. Other tables in the document will remain entirely unaffected.




