Macros and Updating Pivot Table Sources

TheTao2

New Member
Joined
May 1, 2010
Messages
32
Hello All,

I prepare a bunch of different workbooks every month some of which have pivot tables. My boss would like one workbook with all of these combined. I have the below macro which allows me to copy all of the tabs in whichever workbook I select. The problem is that even though I am coping the data that the pivot tables are using the data source still points to the old workbook instead of the new workbook. Is there any way to refresh the data sources on the pivot tables to point to the data within the new workbook?


Sub copy_sheets()

Dim wb1 As Workbook, wb2 As Workbook
Dim Ret1
Set wb1 = ActiveWorkbook
'Change the name of the destination workbook here

Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select the file to import")
If Ret1 = False Then Exit Sub
Set wb2 = Workbooks.Open(Ret1)

For Each Sheet In wb2.Sheets
If Sheet.Visible = True Then
Sheet.Copy After:=wb1.Sheets(wb1.Sheets.Count)
End If
Next Sheet

wb2.Close SaveChanges:=False

Set wb2 = Nothing
Set wb1 = Nothing
End Sub



Thank you
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,206,711
Messages
6,074,470
Members
446,071
Latest member
gaborfreeman

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