Dashboard - Selecting Pivot Items for Multiple Charts

hattrick_123

New Member
Joined
Apr 5, 2011
Messages
7
Hi there

First time poster here. Apprciate any help/pointers.

I have come accross the below code here,that basically selects all the pivot items to be displayed in the pivot chart (including the blank).

What I am looking for is a way to only select one particular pivot item for all charts? Any ideas?

Code:
 ' this works but it shows blanks(need excel 07 to avoid this as you can create a pivot table first and from there a pivot chart, but it can still be avoided using code) as I will be selecting all the blanks for updating this
 ' taken from here [URL]http://excel.bigresource.com/Track/excel-vAvbel9M/[/URL]
Sub ShowAllItems()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim objPT As PivotTable
Dim objPTField As PivotField
Dim objPTItem As PivotItem
 
For Each ws In Worksheets
ws.Visible = xlSheetVisible
    For Each objPT In ws.PivotTables
 MsgBox "Pivot table name: " & objPT.Name & vbCrLf & "Sheet name: " & ws.Name
    With objPT
'
' Run through all the row fields
For Each objPTField In .RowFields
'
' Get the hidden items and make them visible
For Each objPTItem In objPTField.HiddenItems
objPTItem.Visible = True
Next 'objPTItem
Next 'objPTField
'
' Run through all the column fields
For Each objPTField In .ColumnFields
'
' Get the hidden items and make them visible
For Each objPTItem In objPTField.HiddenItems
objPTItem.Visible = True
Next 'objPTItem
Next 'objPTField
End With
Application.ScreenUpdating = True
 
    Next objPT
Next ws
End Sub

The above code is very generic and can apply to any set of data.

The way I am looking at doing it is using an if statement and linking this to a user form, which ultimately selects the desired pivot item.

Example below of what I am trying to do(excuse the syntax I am relativly new to this code :))

Code:
Sub test_select()
    If b2 = 1 Then ' if 1 is selected then George is displayed in the Chart(s)
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SGSN").PivotItems("George").Visible = True
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SGSN").PivotItems("Peter").Visible = False
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SGSN").PivotItems("blank").Visible = False
  ElseIf b2 = 2 Then ' if 2 is selected then Peter is displayed in the Chart(s)
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SGSN").PivotItems("George").Visible = True
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SGSN").PivotItems("Peter").Visible = True
        ActiveSheet.PivotTables("PivotTable1").PivotFields("SGSN").PivotItems("blank").Visible = False
End If
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

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