Code only Returns 1 item

junebug

Board Regular
Joined
Apr 4, 2003
Messages
110
Greetings. I have a Pivot chart with 7 regions to choose from. I want the chart title to display the regions that are checked in the drop down on the pivot chart. I wrote this code but it will only works correctly if one region is checked. If two or more are checked, of the possible seven, it still only shows one. Any help would be appreciated.
Code:
Sub TitleRegion()
Dim PI As PivotItem
Dim mytitle As String

For Each PI In ActiveChart.PivotLayout.PivotTable.PivotFields("Region").PivotItems
If PI.Visible = True Then
 mytitle = PI
        
    End If
    Next PI
 
 With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = mytitle & " Region"
    End With
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,141,913
Messages
5,709,306
Members
421,626
Latest member
indigochild

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
Top