VBA - show all pivotitems based on object array

murdo900

New Member
Joined
Sep 18, 2009
Messages
1
What I'm trying to do is to get excel to show selected or all pivotitems that I have loaded into an array - without looping through each array value, as this requires huge amounts of calculation. A way of thinking about what I want to do is the "with" statement ie

With ActiveSheet.PivotTables("PivotTable1").PivotFields("GOR")
.PivotItems("GOR1").Visible = True
.PivotItems("GOR10").Visible = False
.PivotItems("GOR11").Visible = True
.PivotItems("GOR2").Visible = False
End With

Except that I have heaps more entries than that.


Code:
Sub pivot_items_show_mrexcel()
Sub pvt_items_show()
Dim arr_pvt_items() As Variant
Dim pvt_ref As Variant
Dim counter As Integer
Set pvt_ref = Worksheets("Summary").PivotTables("PivotTable1").PivotFields("GOR")
ReDim arr_pvt_items(pvt_ref.PivotItems.Count)
For counter = 1 To pvt_ref.PivotItems.Count
Set arr_pvt_items(counter) = pvt_ref.PivotItems(counter)
Worksheets("data").Cells(2 + counter, 2).Value = arr_pvt_items(counter).Name
Next counter
 
'what I want to do is to make all items visible, without looping through each array value in order to avoid recalculating tables.
 
arr_pvt_items().Visible = True      'how do I get this line to work?
 
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You can set the table to refresh manually:
Code:
    For Each PT In ActiveSheet.PivotTables
        PT.ManualUpdate = True
    Next PT

This prevents automatic updates. Set it back to False when you want to refresh automatically.

Denis
 
Upvote 0

Forum statistics

Threads
1,223,730
Messages
6,174,169
Members
452,548
Latest member
Enice Anaelle

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