Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Set PivotItem using counter

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Set PivotItem using counter

To answer my own questions - if anybody else cares :-)

Dim maxRange As Integer
Dim count As Integer
Dim i As Integer

Dim Periods As Variant
Periods = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")

Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem

Set pt = Sheets("Pivot").PivotTables("pvtMain")
Set pf = pt.PivotFields("PERIOD_NUMBER")

Application.Calculation = xlManual

pt.RefreshTable

pf.AutoSort xlManual, "PERIOD_NUMBER"

For Each pi In pf.PivotItems
pi.Visible = True
Next pi

maxRange = Range("period").Value + 1

For count = maxRange To 11
i = count - 1

With pf
.PivotItems(CStr(Periods(i))).Visible = False
End With

Next count

"CinqueTerra" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PivotItem.Visible Excelgeek Excel Programming 2 June 14th 05 11:23 PM
PivotItem positioning... Jesterhoz[_2_] Excel Programming 1 May 27th 05 02:26 AM
How to add a PivotItem ? sharprog Excel Programming 2 July 16th 04 04:39 PM
Selecting a PivotItem in code Robert E. Peterson Excel Programming 1 February 4th 04 06:30 PM
Pivotitem count Jesse[_4_] Excel Programming 3 December 28th 03 09:19 PM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"