I am trying to update multiple pivot table fields based on values given in a reference tab.
The pivot tables I am using are linked to an OLAP query and I can not seem to find a way to get the data to pull from cells in another tab.
Do you know how I can update the cells in the reference tab and use a button that updates all of the pivot tables?
Also, I could update the first pivot table in the tab and have the rest reset to those updated fields. I do not know how to do this either.
Here is the code that I have from recording a macro that updates one pivot table to the right settings:
Sheets("Cube").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Year attribute 1]").VisibleItemsList = _
Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Quarter attribute]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Month attribute 1]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Day attribute 1]").VisibleItemsList = _
Array( _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[1]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[2]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[3]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[4]" _
)
I would like to be able to change the "2012", "Quarter 2", "June", and "1,2,3,4" based on either cells in a reference tab or based on the first pivot table in the "Cube" tab.
This is the way I have tried to pull values from the "reference" tab, but it gives me and error and doesnt register that "Current_Month" is equal to a value.
Sub Update_Pivot_Table_All()
'
' Update_Pivot_Table_All Macro
Dim Current_Month As String
Current_Month = Sheets("Reference").Range("D2").Text
Dim Current_Year As Integer
Current_Year = Sheets("Reference").Range("B4").Value
Dim Current_Quarter As String
Current_Quarter = Sheets("Reference").Range("B3").Value
Dim Current_Days As Integer
Current_Days = Sheets("Reference").Range("E2").Value
Sheets("Cube").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Year attribute 1]").VisibleItemsList = _
Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Quarter attribute]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFieds( _
"[Transaction Date].[Transaction Date].[Month attribute 1]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Day attribute 1]").VisibleItemsList = _
Array( _
"[Transaction Date].[Transaction Date].[Year attribute 1].&["Current_Year"].["Current_Quarter"].["Current_Month"].["Current_Days"]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[2]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[3]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[4]" _
)
End Sub
I am grateful for any and all help. Thank you all in advance.
The pivot tables I am using are linked to an OLAP query and I can not seem to find a way to get the data to pull from cells in another tab.
Do you know how I can update the cells in the reference tab and use a button that updates all of the pivot tables?
Also, I could update the first pivot table in the tab and have the rest reset to those updated fields. I do not know how to do this either.
Here is the code that I have from recording a macro that updates one pivot table to the right settings:
Sheets("Cube").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Year attribute 1]").VisibleItemsList = _
Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Quarter attribute]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Month attribute 1]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Day attribute 1]").VisibleItemsList = _
Array( _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[1]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[2]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[3]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[4]" _
)
I would like to be able to change the "2012", "Quarter 2", "June", and "1,2,3,4" based on either cells in a reference tab or based on the first pivot table in the "Cube" tab.
This is the way I have tried to pull values from the "reference" tab, but it gives me and error and doesnt register that "Current_Month" is equal to a value.
Sub Update_Pivot_Table_All()
'
' Update_Pivot_Table_All Macro
Dim Current_Month As String
Current_Month = Sheets("Reference").Range("D2").Text
Dim Current_Year As Integer
Current_Year = Sheets("Reference").Range("B4").Value
Dim Current_Quarter As String
Current_Quarter = Sheets("Reference").Range("B3").Value
Dim Current_Days As Integer
Current_Days = Sheets("Reference").Range("E2").Value
Sheets("Cube").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Year attribute 1]").VisibleItemsList = _
Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Quarter attribute]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFieds( _
"[Transaction Date].[Transaction Date].[Month attribute 1]").VisibleItemsList _
= Array("")
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Transaction Date].[Transaction Date].[Day attribute 1]").VisibleItemsList = _
Array( _
"[Transaction Date].[Transaction Date].[Year attribute 1].&["Current_Year"].["Current_Quarter"].["Current_Month"].["Current_Days"]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[2]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[3]" _
, _
"[Transaction Date].[Transaction Date].[Year attribute 1].&[2012].[Quarter 2].[June].[4]" _
)
End Sub
I am grateful for any and all help. Thank you all in advance.