Excel Macro to Refresh a Pivot Cache and Clear Missing PivotItems
Sub PvtCache_Clear()
Dim My_Pvt As PivotTable
Dim J as Integer
Set My_Pvt = ThisWorkbook.Sheets("My_Tab").PivotTables("MyPivot")
Clearing Missing Items from Pivot Fields and Refreshing Pivot Cache
My_Pvt.PivotCache.MissingItemsLimit = xlMissingItemsNone
My_Pvt.PivotCache.Refresh
'My_Pvt.ManualUpdate = False
'Refreshing the Pivot Table
My_Pvt.RefreshTable
X = My_Pvt.PivotFields("MyField").PivotItems.Count
MsgBox X
'Displaying Pivot Items after Pivot Refresh
For Y = 1 To X
MsgBox My_Pvt.PivotFields("MyField").PivotItems(Y)
Next Y
'De-Selecting the (blanks) from the Pivot
J = My_Pvt.PivotFields("MyField").PivotItems.Count
If J > 2 Then
With My_Pvt.PivotFields("MyField")
.PivotItems("(blank)").Visible = False
End With
Else: End If
End Sub
Sub PvtCache_Clear()
Dim My_Pvt As PivotTable
Dim J as Integer
Set My_Pvt = ThisWorkbook.Sheets("My_Tab").PivotTables("MyPivot")
Clearing Missing Items from Pivot Fields and Refreshing Pivot Cache
My_Pvt.PivotCache.MissingItemsLimit = xlMissingItemsNone
My_Pvt.PivotCache.Refresh
'My_Pvt.ManualUpdate = False
'Refreshing the Pivot Table
My_Pvt.RefreshTable
X = My_Pvt.PivotFields("MyField").PivotItems.Count
MsgBox X
'Displaying Pivot Items after Pivot Refresh
For Y = 1 To X
MsgBox My_Pvt.PivotFields("MyField").PivotItems(Y)
Next Y
'De-Selecting the (blanks) from the Pivot
J = My_Pvt.PivotFields("MyField").PivotItems.Count
If J > 2 Then
With My_Pvt.PivotFields("MyField")
.PivotItems("(blank)").Visible = False
End With
Else: End If
End Sub
--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------
No comments:
Post a Comment
Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.