Populating tables in Word from Excel pivot tables

jennc90

New Member
Joined
May 2, 2013
Messages
2
Hi all,

I am looking for some help with finding the fastest and simplest way to populate tables I've created in Microsoft Word using data from pivot tables in Microsoft Excel.

I have a Word document (a template I've created) with 15 different tables. This template must be populated at least 50 times with 50 different sets of data. What I thought would work best would be to structure my pivot tables in such a way to mimic my Word tables, so I could change variables with a filter and copy paste the data, but that seems too laborious considering I have to populate this template so many times. Also, the work involved in doing that may exceed the time I have to work on the project.

My template includes columns for counts, proportions and share. There can be as many as 20 columns. I have, at most, 25 rows. That's a lot of numbers! One of my tables has count, proportion and rank.

So, for example, one table has 15 variables (in the rows). For each variable I need to fill in numbers in 3 columns: Count, proportion and rank.

A few people have suggested using a macro but I'm not quite sure how to go about creating one that will grab the data from the pivots and load them into the Word tables.

I would appreciate any help you could provide.

Thank you!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Populating Word tables with Excel data via a macro is not particularly difficult, even without a Pivot table - all you need to express in the code is the logic for what data go where.

A fairly basic macro to create & populate a document from a template is:
Code:
Sub Demo()
'Note: A Reference to the Microsoft Word Object Library
' is required, via Tools>References.
Dim xlWkSht As Worksheet
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = New Word.Application
Dim i As Long
Set xlWkSht = ActiveSheet
With wdApp
  .Visible = True
  .ScreenUpdating = False
  Set wdDoc = .Documents.Add(Template:="Template path & name")
  With wdDoc
    For i = 1 To .Tables.Count
      Select Case i
        Case 1
          With .Tables(i)
            .Cell(1, 1).Range.Text = xlWkSht.Range("A1").Text
            .Cell(1, 2).Range.Text = xlWkSht.Range("B1").Text
            .Cell(2, 1).Range.Text = xlWkSht.Range("A2").Text
            .Cell(2, 2).Range.Text = xlWkSht.Range("B2").Text
          End With
        Case 2
          With .Tables(i)
            .Cell(1, 1).Range.Text = xlWkSht.Range("D1").Text
            .Cell(1, 2).Range.Text = xlWkSht.Range("E1").Text
            .Cell(2, 1).Range.Text = xlWkSht.Range("D2").Text
            .Cell(2, 2).Range.Text = xlWkSht.Range("E2").Text
          End With
      End Select
    Next
  End With
  .ScreenUpdating = True
End With
End Sub
Of course, I don't know any of the logic behind your pivot tables, so I can't replicate that. That said, if you know your requirements well enough, you can conditionally add rows to tables to account for varying amounts of data from one run of the macro to the next. And you can delete tables for which there is no content, if need be.
 
Upvote 0

Forum statistics

Threads
1,225,637
Messages
6,186,137
Members
453,339
Latest member
Stu61

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top