C
CinqueTerra
Scenario: User inputs a month in a cell with range name "period". I need the
Pivot Table to show all months less than or equal to "period". Is there a
way to use a counter to set the visible property of PivotItem? My code:
Dim maxRange As Integer
Dim count As Integer
Dim strPeriod As String
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = Sheets("Pivot").PivotTables("pvtMain")
Set pf = pt.PivotFields("PERIOD_NUMBER")
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
maxRange = Range("period").Value + 1
For count = maxRange To 12
strPeriod = count
If pi.Name = strPeriod Then
pi.Visible = False
End If
Next count
Pivot Table to show all months less than or equal to "period". Is there a
way to use a counter to set the visible property of PivotItem? My code:
Dim maxRange As Integer
Dim count As Integer
Dim strPeriod As String
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = Sheets("Pivot").PivotTables("pvtMain")
Set pf = pt.PivotFields("PERIOD_NUMBER")
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
maxRange = Range("period").Value + 1
For count = maxRange To 12
strPeriod = count
If pi.Name = strPeriod Then
pi.Visible = False
End If
Next count