How to Delete Word Table Rows Containing Specific Text with VBA
Question details
The user needs to delete entire table rows in a Word document that contain a specific text string using a VBA macro, as standard find and replace methods fail.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating the cleanup of Word document tables by locating and removing rows that contain a specific text value.
- Observed behavior
- Standard Find and Replace patterns fail to capture the target text correctly when it appears right before the end-of-cell marker, requiring a VBA macro to execute the deletion safely.
Always create a backup copy of your Word document before running any new VBA macros to prevent accidental data loss, as macro actions usually cannot be undone.
Use a Custom VBA Macro to Delete Targeted Table Rows
Create and run a custom VBA script that accurately searches for specific text within a table, excludes the cell marker, and deletes the entire row.
Because Word's standard Find and Replace functionality can struggle with text adjacent to end-of-cell markers, a VBA macro is the safest approach. The macro iterates through the document, locates your specific search string, verifies it is inside a table, and deletes the row containing the match without breaking the overall table structure.
With your Word document open, press ALT + F11 on your keyboard to launch the Microsoft Visual Basic for Applications editor.
Click on 'Insert' in the top menu and select 'Module' to create a blank workspace for your code.
Paste your VBA code into the module. Ensure your script uses the Find object to search for your target text (e.g., 'CSA 130-03') and calls the `.Rows(1).Delete` method when a match is confirmed inside a table.
Press F5 or click the green 'Run' button in the toolbar to execute the macro. The script will scan the document and remove the applicable rows.

Automate Word Documents Using WPS Office
WPS Office supports advanced document editing and VBA macros in its professional versions. You can seamlessly open your Word documents and run customized scripts to automate table editing and formatting tasks.
- 1. Open the Document: Launch WPS Writer and open your Word document containing the target tables.
- 2. Enable Developer Tools: Go to the Developer tab on the ribbon. If it is not active, enable it in the WPS Options menu.
- 3. Access the VBA Editor: Click on 'Visual Basic' or press ALT + F11 to open the macro editor interface.
- 4. Run the Deletion Macro: Insert a new module, paste your VBA code to locate and delete specific rows, and press F5 to execute.

Frequently Asked Questions
Why does standard Find and Replace fail for table cells?
Word's standard Find and Replace can struggle when the target text is adjacent to the end-of-cell marker. Selecting the text without this marker using VBA is necessary for accurate detection and deletion.
Can I undo a VBA macro execution in Word?
Generally, changes made by a VBA macro cannot be undone using the standard Undo (Ctrl+Z) function. This is why it is highly recommended to test macros on a copy of your document first.
How do I specify a different text string to delete in the macro?
You can change the target text directly within the VBA code. Look for the line containing the original search string (e.g., 'CSA 130-03') and replace it with your desired text.




