logo
search
VBA & Macro Problems

How to Delete Word Table Rows Containing Specific Text with VBA

Camila MilosovichCamila Milosovich Oct 7, 2026 869 views

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.

How to Delete Word Table Rows Containing Specific Text Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

With your Word document open, press ALT + F11 on your keyboard to launch the Microsoft Visual Basic for Applications editor.

2
Insert a New Module

Click on 'Insert' in the top menu and select 'Module' to create a blank workspace for your code.

3
Paste the Deletion 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.

4
Run the Macro

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.

Use a Custom VBA Macro to Delete Targeted Table Rows
Handling Cell Markers: Ensure your macro's search logic adjusts the text range to exclude the end-of-cell marker so the text is matched accurately.
Advanced Document Processing

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. 1. Open the Document: Launch WPS Writer and open your Word document containing the target tables.
  2. 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. 3. Access the VBA Editor: Click on 'Visual Basic' or press ALT + F11 to open the macro editor interface.
  4. 4. Run the Deletion Macro: Insert a new module, paste your VBA code to locate and delete specific rows, and press F5 to execute.
Highly compatible with Microsoft Word formats (.docx, .doc)Supports Developer tools and macro execution for automationFamiliar ribbon interface makes finding tools easyLightweight design ensures fast loading of large documents
QA img-9

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.