VBA & Macro Problems

How to Move Word Table Rows by Date with VBA and Preserve Formatting

Steven ParkerSteven Parker Oct 29, 2026 871 views

Question details

The user needs a Word VBA script to identify table rows containing a date after November 1, 2020, and move them into a table in a separate document. The rows must be inserted individually while perfectly preserving their original formatting.

How to Move Word Table Rows by Date with VBA While Preserving Formatting
Product
Word
Device & OS
not provided
Scenario
Filtering and archiving specific table rows based on a date column to a different document.
Observed behavior
The goal is to copy the formatted content of qualifying rows individually and delete the originals, intentionally avoiding traditional cut-and-paste to prevent clipboard side effects.
Before you start

Ensure you have saved backups of both your source and destination Word documents before running the VBA macro, as deleting rows programmatically cannot be easily undone.

Solution 1Recommended

Use Range Objects to Transfer Formatted Text

The safest and most reliable method to move formatted table rows in VBA is by setting the destination range's formatted text equal to the source range's formatted text, bypassing the Windows clipboard entirely.

Using standard copy and paste in VBA can lead to unexpected clipboard side effects and formatting loss. By utilizing two distinct Range objects (one for the source and one for the destination), you can directly assign the formatted text from one document to another.

Since VBA handles date comparisons strictly, it is crucial to store your target date in a properly typed Date variable before evaluating the text extracted from your table cells.

1
Set Up Range Objects

Declare two `Range` objects in your VBA script: `srcRange` for the row you are evaluating in the source document, and `destRange` for the insertion point in the destination document.

2
Define the Comparison Date

Store your target date (e.g., November 1, 2020) in a VBA `Date` variable to ensure accurate mathematical comparison against the text extracted from the date column.

3
Transfer the Formatted Text

For qualifying rows, use the command `destRange.FormattedText = srcRange.FormattedText`. Make sure your `srcRange` includes the end-of-row marker so the table structure is maintained during the transfer.

4
Append and Delete

To append the row correctly, set `destRange` to a collapsed range immediately before the paragraph mark following the destination table. Finally, delete the original row from the source document using `srcRange.Rows(1).Delete`.

Use Range Objects to Transfer Formatted Text
Handling Dates in VBA: Be sure to strip non-printable characters (like the end-of-cell markers Chr(13) and Chr(7)) from the cell text before converting it to a date for comparison.
Free Microsoft Office alternative

Try WPS Office for Seamless Document Management

If you are struggling with complex VBA macros in Microsoft Word, consider switching to WPS Office. It provides a lightweight, highly compatible, and user-friendly interface for handling all your word processing needs, complete with advanced table management tools.

  1. 1. Download and Install: Download WPS Office Free from the official website and install it on your device.
  2. 2. Open Your Word Document: Launch WPS Writer and open your existing .docx or .docm files directly without losing any original formatting.
  3. 3. Manage Tables Easily: Use the intuitive Table Tools ribbon in WPS Writer to sort, move, and format table rows efficiently.
Fully compatible with Microsoft Word formats (.docx, .doc, .docm).Includes powerful built-in table management and formatting tools.Free, lightweight, and fast to launch on Windows, Mac, and Linux.Familiar user interface ensuring a seamless migration from Microsoft Office.
microsoft office alternative - wps office

Frequently Asked Questions

Why should I avoid using cut and paste in VBA for moving table rows?

Using the clipboard for cut and paste operations in VBA can cause unwanted side effects, such as overwriting user data currently on the clipboard, triggering system alerts, and occasionally losing complex formatting. Directly assigning FormattedText is much safer and faster.

How do I extract a clean date from a Word table cell in VBA?

Word table cells contain end-of-cell markers (Chr(13) & Chr(7)) at the end of their text. You must use the Replace function or string manipulation (like Left(cellText, Len(cellText) - 2)) to remove these invisible markers before converting the string to a Date type.

Why are my copied rows losing their table structure in the destination document?

This usually happens if the source range does not include the end-of-row marker. Ensure your srcRange encompasses the entire row object, not just the text inside the individual cells, before copying the FormattedText.

Can I run Microsoft Word VBA macros in WPS Office?

Yes, WPS Office Pro and certain enterprise editions support VBA macros. You can run many standard Word VBA scripts, though some highly specific Microsoft Office object model properties might occasionally require slight adjustments.