Multiple Pivot Table using same cache

predzer

New Member
Joined
Jun 21, 2018
Messages
20
Hi Guys!

I'm working on automating data analysis & creation of pivots and charts for which I have Raw Data (441379 Rows, 40 columns).

1) Raw Data keeps changing monthly, so I need a dynamic range.

2) I have to create around 20 Pivot Tables with the same data.

3) As of now I'm defining range and pivot cache for every single pivot I do, Because of that a lot of time is consumed in reading data and executing every single time.

4) I need to have the flexibility of choosing a range for placing the pivot table as one sheet may have more than one pivot table.

5) I need to have the flexibility of creating a sheet and naming them for pivot as i will have around 20 sheets.

Please Help me out by creating a efficient CODE to define pivot source and pivot cache just once in the workbook so that i can use the same for all the pivot tables, which will save a ton of my time.

Below is the code which I'm using

' For Dynamic data range named "PvtData"


ActiveWorkbook.Names.Add Name:="PvtData", RefersToR1C1:= _
"=OFFSET('Data'!R1C1,0,0,COUNTA('Data'!C1),COUNTA('Data'!R1))"

' For creating Pivot using Dynamic data range named "PvtData"

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"PvtData").CreatePivotTable TableDestination:="", TableName:="PivotTable_UBD"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(7, 1)
ActiveSheet.Cells(7, 1).Select
ActiveSheet.PivotTables("PivotTable_UBD").SmallGrid = False
ActiveSheet.Name = "Utilization By Day"


OR


' For Dynamic data range named "PvtData"


ActiveWorkbook.Names.Add Name:="PvtData", RefersToR1C1:= _
"=OFFSET('Data'!R1C1,0,0,COUNTA('Data'!C1),COUNTA('Data'!R1))"

' For creating Pivot using Dynamic data range named "PvtData"

Set PivotCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:="PvtData")
Worksheets.Add
ActiveSheet.Name = "Utilization By Day"
ActiveWindow.DisplayGridlines = True

Set PivotTable = ActiveSheet.PivotTables.Add(PivotCache:=PivotCache, _
TableDestination:=Range("A1"), TableName:="PivotTable_UBD")


THANK YOU SO MUCH IN ADVANCE!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Welcome to the forum.

Please take a minute to read the forum rules on cross-posting and comply with them. Thanks. :)
 
Upvote 0
Hi RoryA,

My apologies. I did read through the cross-posting forum rules and was having thoughts before posting.

BUT I did search through the forum but could'nt find relevant post so went ahead and posted it. My concerns were either those codes in other post was using declarations which i am not well versed with, as you can see I haven't used any declarations in my code. So if i had to comply all my codes with declarations it would take quite a lot of time to revamp all the modules I have created so far. I have around 22 modules so far and looking to add another 15.

Thanks for your time.
 
Upvote 0
I don't think you understood the rule. You need to provide links here to your posts on other forums (eg Stack Overflow) on this topic.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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