VBA & Macro Problems

Fix a Word VBA Macro in WPS Office That Only Processes the First Matching Table Entry

Kushani NimanthikaKushani Nimanthika Nov 13, 2026 869 views

Question details

Modify an existing Word VBA macro so it finds every matching vendor and processes rows across one or more tables instead of stopping at the first occurrence.

Fix a Word VBA Macro That Only Processes the First Matching Table Entry in WPS Office
Product
WPS Office Writer
Device & OS
not provided
Scenario
The user is working with a Word document in WPS Writer that contains one or more vendor tables and needs a VBA macro to update every matching vendor row.
Observed behavior
The existing macro only processes the first matching table entry and skips the remaining rows.
Before you start

Open the target document in WPS Writer and make a copy. Enable the Developer tab or press Alt+F11 to open the VBA editor so you can inspect the existing macro before editing.

Solution 1Recommended

Modify the Word VBA Macro to Loop Through Every Table and Row

Use this when the vendor data is stored in one or more Word tables and you need to update every matching row.

The macro should not search the entire document repeatedly. Instead, iterate through the Tables collection and then through each Rows collection, trimming the end-of-cell marker before comparing vendor text.

This approach runs faster and prevents the macro from stopping at the first match.

1
Open the VBA editor

In WPS Writer, press Alt+F11 or go to Developer tab > Visual Basic to open the macro editor and locate your existing macro.

2
Declare the table and row variables

Inside your Sub, add Dim tbl As Table, i As Long, rngVendor As Range and set the target table with Set tbl = ActiveDocument.Tables(1) or loop through ActiveDocument.Tables.

3
Loop through each row and read the vendor cell

Use For i = 2 To tbl.Rows.Count, then set rngVendor = tbl.Cell(i, 3).Range and remove the end-of-cell marker with rngVendor.End = rngVendor.End - 1.

4
Compare text and write the description

Replace the vendor comparison with rngVendor.Text after trimming, then assign the description to the target cell, for example tbl.Cell(i, 5).Range.Text = Medical Expense.

5
Run and test the macro

Press F5 or click Run in the VBA editor, then verify that every matching vendor row in the table updates rather than only the first.

Modify the Word VBA Macro to Loop Through Every Table and Row
All matching rows updated: The loop updates every vendor row in each table and avoids repeated document-wide searches.

Edit the Word VBA Macro in WPS Office to Loop Through All Table Rows

WPS Office lets you edit the Word VBA macro directly in WPS Writer. Use the built-in VBA editor to loop through all tables and rows, trim the vendor cell text, and write the description to each matching target cell, then save the file in Word-compatible .doc or .docm format.

  1. 1. Download and install WPS Office: Get WPS Office from the official website and install it on your PC, then open WPS Writer.
  2. 2. Open the Word document: Click File > Open and select the .doc or .docm file containing the vendor table macro.
  3. 3. Open the VBA editor: Go to Developer tab > Visual Basic or press Alt+F11 to access the macro project.
  4. 4. Modify the macro loop: Replace the single-match search with a For i = 2 To tbl.Rows.Count loop that trims the end-of-cell marker and writes each target cell.
  5. 5. Run and save the macro-enabled document: Press F5 to run the macro, confirm all matching rows update, then save the file as .docm or .doc.
Edit Word VBA macros without leaving WPS OfficeProcess every matching vendor row across multiple tablesFull .doc, .docm, and .dotm compatibility with Microsoft WordFree, lightweight Office suite with a familiar ribbon and Developer tabRun and test macros in the built-in VBA editor
QA img-9

Frequently Asked Questions

Why does my Word VBA macro stop after the first matching vendor?

It likely uses Selection.Find or exits after the first match. Switch to a loop through ActiveDocument.Tables and tbl.Rows, and trim the vendor cell range with rngVendor.End = rngVendor.End - 1 before comparing the text.

How do I remove the end-of-cell marker in a Word table cell VBA?

Set the cell range and subtract one from its End property: Set rng = tbl.Cell(i, 3).Range, then rng.End = rng.End - 1. Use rng.Text for the comparison.

How do I process multiple tables instead of just the first table?

Use For Each tbl In ActiveDocument.Tables, then loop through each table with For i = 2 To tbl.Rows.Count and update the target cell for every matching row.

Can I run this Word VBA macro in WPS Office?

Yes. Open WPS Writer, enable the Developer tab, press Alt+F11 to open the VBA editor, and run or edit the macro in a supported .docm or .doc file.

What is the difference between wdFindStop and wdFindContinue?

wdFindStop prevents the search from wrapping past the document end, so you can collapse the range and find each next match without creating an infinite loop.