• Status: Solved
  • Priority: High
  • Security: Private
  • Views: 50
  • Last Modified:

VBA Macro Code to copy data from a particular row in multiple tables to a different table in Word document

I had this question after viewing VBA Code to copy Text from different rows in one table to a single row in a different table.

The goal I need for the macro I need will be very easy to understand if you look at the diagram provided with this question.
The left half of the diagram shows how 5 tables look in my Word document. The right half of the diagram I would like the tables to look after the macro has done its job.

Bascially I have 5 tables in a Word Document. The first 4 tables have data in some rows and columns and some rows do not have any data in column 2. At the bottom of the document I have the 5th which does not have any data before the Macro Runs. I would like my Macro to copy data from both first and second column of the third row from Table 1 to Table 4 to Table 5.
1 Solution

pls try
Sub macro()
For Idx = 1 To 4
    Set srctbl = ActiveDocument.Tables(Idx)
    Set tgttbl = ActiveDocument.Tables(5)
    Set rng = srctbl.Rows(3).Range
    rng.MoveEnd wdCharacter, -1 
    Set rng1 = tgttbl.Rows(Idx).Range
    rng1.Collapse wdCollapseStart
End Sub

Open in new window

FaheemAhmadGulAuthor Commented:
Worked great!
Many thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now