How to Merge Word Table Columns Across Multiple Rows Using VBA
Question details
The user wants to use a VBA macro to merge selected table columns across multiple rows in a Word document, eliminating the need to manually merge cells row by row.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating repetitive table formatting tasks where specific columns need to be merged across several rows simultaneously.
- Observed behavior
- The user needs a macro that can validate the current table selection and accurately process and merge the corresponding cells row by row.
Ensure your Word document is saved in a macro-enabled format (.docm) and that you have enabled the Developer tab in your ribbon to access the VBA editor.
Use a VBA Macro to Merge Selected Columns Row by Row
Run a custom VBA script that identifies your selection within a table and automatically merges the cells across the highlighted columns for every selected row.
This macro is designed to process selections that span across multiple rows. It first verifies that your selection is inside a valid table.
When adapting or writing the macro for specific column merge conditions, ensure you use 'If c - i < 1 Then' instead of '< 2' if you are targeting a single-column merge logic within your loop.
Press Alt + F11 in Word to open the Microsoft Visual Basic for Applications window.
Click 'Insert' in the top menu and select 'Module' to create a blank script window.
Paste your custom table-merging macro code into the module window. Ensure the script includes validation for 'Selection.Information(wdWithInTable)' to prevent errors.
Close the VBA editor, return to your document, and highlight the cells in the columns and rows you want to merge.
Press Alt + F8, select your newly created macro from the list, and click 'Run' to execute the row-by-row merge.
Format and Merge Tables Effortlessly in WPS Office
WPS Writer provides an intuitive interface for advanced table formatting and is fully compatible with Microsoft Word documents. You can easily merge cells across rows and columns using built-in tools or utilize VBA macros in the Professional version for automated tasks.
- 1. Open your Document: Launch WPS Writer and open the document containing the table you want to modify.
- 2. Select the Target Cells: Click and drag to highlight the specific cells across the columns and rows you wish to merge.
- 3. Access Table Tools: Navigate to the 'Table Tools' tab that appears on the top ribbon when a table is selected.
- 4. Merge the Cells: Click the 'Merge Cells' button to instantly combine your selected cells. For repetitive tasks, use the Developer tab to run your VBA macros just as you would in Microsoft Word.

Frequently Asked Questions
Why is my VBA macro throwing an error when I select cells?
This usually happens if the macro attempts to execute table-specific commands on standard text. Ensure your code includes validation to check if the current selection is inside a table using 'Selection.Information(wdWithInTable)'.
What is the difference between 'If c - i < 1 Then' and 'If c - i < 2 Then' in the merge loop?
Using '< 1' restricts the condition to handle a stricter single-column merge or step calculation, ensuring the loop doesn't incorrectly skip or merge unintended adjacent cells depending on how your specific array or loop variables are set up.
Can I merge cells across multiple rows in Word without using VBA?
You can manually select the cells in a single row, right-click, and choose 'Merge Cells', but you must repeat this action for every row. Standard Word tools do not support batch-merging corresponding columns across multiple rows simultaneously, which is why a VBA macro is highly recommended for bulk operations.




