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!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Welcome to the forum.

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

predzer

New Member
Joined
Jun 21, 2018
Messages
20
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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.
 

Forum statistics

Threads
1,082,257
Messages
5,364,074
Members
400,778
Latest member
Canadian Sal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top