I have a sheet that contains a table (produced from jasper report query). This table will be the source of my pivot table. The Pivot is created using an external connection (From Microsoft Query). since the source table needs to be defined before it can be used in Micrososft Query, could anyone show me how to do it programatically?
INFO:
- There are 2 documents here, the first is a protected source data and the second is a Pivot document.
- The data is dynamic and the table contains a header.
Is there any way to define the table area using excel programatically with dynamic data?
To answer your comments from the two previous answers (whose, in my opinion, fit your need).
Here is a way to define named range with vba:
Source
Here is a way to create a table with vba (remember it will only work on Excel 2007 or higher):
Source
If you use a table (defined) , you can call table object sample
Otherwise is create a dynamic range using a name for example
=OFFSET(Plan1!A1;0;0;counta(Plan1!A:A);counta(Plan1!1:1))
Select a name to this range, and in your pivot define a range at =NameOfInterval
[]'s
Here's how to approach if you do not know the range size: First get the index refs of the last row / column. Then use the indexes to create "Table1"