Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to loop through PivotTable

I have a Pivot Table already created. However, I am programming a module and
I want to access the information contained in the pivot table and loop
through it to change the data and print a page for each item in the table. I
understand how to write a loop but I am having trouble locating how to access
the data in the pivot table.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default How to loop through PivotTable

Here is an example of a loop that I did with a pivot table
With ActiveChart.PivotLayout.PivotTable.PivotFields("Fr equency")
For cnt = 1 To .PivotItems.Count
If .PivotItems(cnt).Value < minFreq Or .PivotItems(cnt)
maxFreq Then
.PivotItems(cnt).Visible = False
Else
cnt2 = cnt2 + 1
End If
Next
End With

Does that help any?


Die_Another_Day

"ShadowVixen" wrote in message
...
I have a Pivot Table already created. However, I am programming a module
and
I want to access the information contained in the pivot table and loop
through it to change the data and print a page for each item in the table.
I
understand how to write a loop but I am having trouble locating how to
access
the data in the pivot table.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to loop through PivotTable

I am not sure - now I am getting an error message that says "Cant find
project or library". My code is below:

Sub PrintForms()
Dim StartRow
Dim EndRow
Dim Msg As String
Dim i

Sheets("1").Activate
With ActiveChart.PivotLayout.PivotTable.PivotFields("Mo nid")
For i = 1 To .PivotItems.Count
Range("B1") = PivotFields("Monid").Value
ActiveSheet.PrintOut
Next
End With


End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default How to loop through PivotTable

This is because you haven't selected the Pivot Chart. Is the chart on a
separate page?

Die_Another_Day
ShadowVixen wrote:
I am not sure - now I am getting an error message that says "Cant find
project or library". My code is below:

Sub PrintForms()
Dim StartRow
Dim EndRow
Dim Msg As String
Dim i

Sheets("1").Activate
With ActiveChart.PivotLayout.PivotTable.PivotFields("Mo nid")
For i = 1 To .PivotItems.Count
Range("B1") = PivotFields("Monid").Value
ActiveSheet.PrintOut
Next
End With


End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to loop through PivotTable

Sorry for the delay in response. Yes, the pivot table is on the same
worksheet. However, the data is on a separate sheet in the same workbook.

"Die_Another_Day" wrote:

This is because you haven't selected the Pivot Chart. Is the chart on a
separate page?

Die_Another_Day
ShadowVixen wrote:
I am not sure - now I am getting an error message that says "Cant find
project or library". My code is below:

Sub PrintForms()
Dim StartRow
Dim EndRow
Dim Msg As String
Dim i

Sheets("1").Activate
With ActiveChart.PivotLayout.PivotTable.PivotFields("Mo nid")
For i = 1 To .PivotItems.Count
Range("B1") = PivotFields("Monid").Value
ActiveSheet.PrintOut
Next
End With


End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Resolved: How to loop through PivotTable

I finally got it - for anyone who is having the same challenge. The code is
below:

Sub PrintForms()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem

' Set reference to pivot table
Set pt = ActiveSheet.PivotTables(1)
' Set reference to the pivot field
Set pf = pt.PivotFields("monid")

For Each pi In pf.PivotItems

Range("B1") = pi.Value
ActiveSheet.PrintPreview
'ActiveSheet.PrintOut
Next

End Sub
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
Creating a PivotTable w/o selecting data in an existing PivotTable Damian Excel Discussion (Misc queries) 6 November 2nd 07 04:44 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
How does one get the PivotTable report info that feeds another PivotTable report? Toby Erkson[_3_] Excel Programming 0 December 14th 04 10:00 PM
PivotTable - PivotTable Field name is not valid - error! miker1999[_17_] Excel Programming 1 June 10th 04 10:30 AM


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

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

About Us

"It's about Microsoft Excel"