Getting Run time Error 5 when Creating a Pivot Table

gate68

New Member
Joined
Jun 6, 2008
Messages
34
I am creating 10 pivot tables for data in one worksheet and putting them in a separate work sheet. i used the macro recorder but the cod eit worte stop at this line

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'RCH&BEA'!C2").CreatePivotTable TableDestination:="'RCH&BEA PIVOT TABLES'", TableName:= _
"RCH&BEA PIVOT TABLES", DefaultVersion:=xlPivotTableVersion10

The error i get is that run time error 1004 where it says this command requires atleast two rows of source data. It also says something about specifically about pivot tables but it cuts it off
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
If you change this bit:
"'RCH&BEA'!C2"
to reference specific rows in column B, then it should work.
 
Upvote 0
Assuming your data is in column B from say rows 1 to 10, try this:
Code:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'RCH&BEA'!R1C2:R10C2").CreatePivotTable TableDestination:="'RCH&BEA PIVOT TABLES'", TableName:= _
"RCH&BEA PIVOT TABLES", DefaultVersion:=xlPivotTableVersion10
 
Upvote 0
What is

'RCH&BEA PIVOT TABLES'?
A worksheet? If so, you need to specify a range on the worksheet. As a matter of interest, why are you creating a pivot table from one column of data?
 
Upvote 0
Basically i have A column of dates where each is a complaint therefore i want to count how many complaints are in each day and make easy enough to pick a whole month to transfer it into minitab
 
Upvote 0
It highlights the same whole line for that run-time Error 5. I dunno how to add the range to the worksheet but do i just add it to the Table Destination:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"RCH&BEA!R2C2:R10C2").CreatePivotTable TableDestination:="'RCH&BEA PIVOT TABLES'!A2", TableName:= _
"RCH&BEA PIVOT TABLES", DefaultVersion:=xlPivotTableVersion10
 
Upvote 0
Let's try breaking the line up so we can see where the problem is. Try this:
Code:
Dim pc As PivotCache, pt As PivotTable
Set pc = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
         SourceData:="RCH&BEA!R2C2:R10C2")
Set pt = pc.CreatePivotTable(TableDestination:=Worksheets("RCH&BEA PIVOT TABLES").Range("A2"), _
   TableName:="RCH&BEA PIVOT TABLES", DefaultVersion:=xlPivotTableVersion10)
 
Upvote 0
Thanks alot that finally worked that section to work. Now as i went down i am getting a Run -time error 1004-Unable to get PivotFields Property of the Worksheet class. I have Named my Column Date i am not sure what has went wrong.:

With ActiveSheet.PivotTables("RCH&BEA PIVOT TABLES").PivotFields("Date")
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,980
Members
448,934
Latest member
audette89

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