Pivot Table Source Data Question

tthiele

Board Regular
Joined
Jun 17, 2002
Messages
67
Office Version
  1. 365
Platform
  1. MacOS
I have the following code which creates a pivot table:
_________________________________________

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"IntermediateCalculations!R19C15:R866C18").CreatePivotTable TableDestination _
:="'PivotTable'!R3C1", TableName:="CopyTable", DefaultVersion:=xlPivotTableVersion10
_________________________________________

Obviously, it will create a pivot table for data that resides in the range O15:R866. However, I want it to be able to create a pivot table for an expanding range.

I thought that the following modifications would work:
____________________________________________
str1 = "IntermediateCalculations!R19C15"
str2 = Sheet12.Range("O19").End(xlDown).End(xlToRight).Address(ReferenceStyle:=xlR1C1)
str3 = ""
str4 = str1 & str2 & str3

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=str4).CreatePivotTable TableDestination _
:="'PivotTable'!R3C1", TableName:="CopyTable", DefaultVersion:=xlPivotTableVersion10
____________________________________________

However, when I run this code, the following error occurs:

Run-time error '1004':
Application-defined or object-defined error.

Which seems to indicate to me that something is wrong with my use of strings to accomplish my goal.

Is there some other way to do this, or is there something wrong with my syntax that I can modify?

Thanks in advance,

Troy
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The activeworkbook.pivotcaches.add line.

I am pretty sure it has to do with how I have the data source set up.

Thanks,

Troy
 
Upvote 0
Create and use a Defined Name for your PivotTable's source data. Add new rows to your source data using a Data Form or have your Defined Name refer to a formula that recognizes additional rows.
 
Upvote 0
Thanks, but I tried that, and received the same set of errors. I am convinced that there is some special format of how that line is supposed to look. Any other troubleshooting ideas?

Thanks,

Troy
 
Upvote 0
Try not using actual row & column references SourceData:= _
"IntermediateCalculations!R19C15:R866C18"

Try using this:
SourceData:=Selection.CurrentRegion
 
Upvote 0

Forum statistics

Threads
1,216,087
Messages
6,128,740
Members
449,466
Latest member
Peter Juhnke

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