[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: High
  • Security: Private
  • Views: 32
  • 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.

Join & Write a Comment

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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