Fix a Word VBA Macro in WPS Office That Only Processes the First Matching Table Entry
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.

- 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.
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.
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.
In WPS Writer, press Alt+F11 or go to Developer tab > Visual Basic to open the macro editor and locate your existing macro.
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.
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.
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.
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.

Use a Range.Find Loop for Vendor Text Outside Tables
Choose this if the vendor entries are in body paragraphs rather than table cells and you need to find each match sequentially.
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. Download and install WPS Office: Get WPS Office from the official website and install it on your PC, then open WPS Writer.
- 2. Open the Word document: Click File > Open and select the .doc or .docm file containing the vendor table macro.
- 3. Open the VBA editor: Go to Developer tab > Visual Basic or press Alt+F11 to access the macro project.
- 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. 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.

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.




