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
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Watch MrExcel Video

Forum statistics

Threads
1,114,058
Messages
5,545,757
Members
410,704
Latest member
Cobber2008
Top