Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
There are times when you want to create Microsoft Excel reports with pivot tables that take data from different data sources (such as a database) that are not known at design time. This article provides an approach to dynamically change a pivot table’s data source.
Creating a new designer template.
Create a new designer template file as shown in the screenshot below.
Then define a named range, DataSource, which refers to this range of cells.
Creating a designer template & defining a named range, DataSource

Creating a Pivot Table based on this named range.
In Microsoft Excel, choose Data, then PivotTable, and PivotChart Report.
Create a pivot table based on the named range created in the first step.
Creating a pivot table based on the named range, DataSource

Drag the corresponding fields to the pivot table rows and columns, then create the resulting pivot table as shown in the screenshot below.
Creating a pivot table based on a corresponding field

Right‑click the pivot table and select Table Options.
Check Refresh on open in the Data options settings.
Setting the pivot table options

Now, you can save this file as your designer template file.
Executing the example code below changes the source data of the pivot table.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.