#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Pivot Table

Hello,
I have a pivot table where I analyze supplier performance. I have the
supplier name in the Page field. How can I determine in VBA the list of
suppliers contained in the field? I want to be able to give a person a drop
down box with a list of suppliers where they can pick the supplier name. I
know they are listed in the page field but I am putting the pivot table on a
hidden, protected sheet so they can't change it.

Thanks,

Bill


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Pivot Table

Bill

Here's a function that will return a collection of all items in the
pagefield. It finds which column the pagefield uses and loops through that
column adding unique entries to the collection. There's not a lot in the
way of error checking in it, but it should give you a start.

Function UniquePageFields(pt As PivotTable) As Collection

Dim colUniques As Collection
Dim pf As PivotField
Dim lCol As Long
Dim rCell As Range
Dim rngSource As Range

Set pf = pt.PageFields(1)
Set rngSource = Range(Application.ConvertFormula(pt.SourceData, xlR1C1,
xlA1))

lCol = Application.WorksheetFunction.Match(pf.SourceName,
rngSource.Rows(1), False)

Set colUniques = New Collection

For Each rCell In rngSource.Columns(lCol).Cells
On Error Resume Next
colUniques.Add rCell.Text, rCell.Text
On Error GoTo 0
Next rCell

Set UniquePageFields = colUniques

End Function


Sub test()

Dim vItm As Variant
Dim colPages As Collection

Set colPages = UniquePageFields(Sheet1.PivotTables(1))

For Each vItm In colPages
Debug.Print colPages.Item(vItm)
Next vItm

End Sub


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Bill wrote:
Hello,
I have a pivot table where I analyze supplier performance. I have the
supplier name in the Page field. How can I determine in VBA the list
of suppliers contained in the field? I want to be able to give a
person a drop down box with a list of suppliers where they can pick
the supplier name. I know they are listed in the page field but I am
putting the pivot table on a hidden, protected sheet so they can't
change it.
Thanks,

Bill



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Pivot Table

Or, if the source data is an Excel worksheet, you could use an Advanced
Filter to extract the unique items from the page field's column, and
sort the results.

Dick Kusleika wrote:
Bill

Here's a function that will return a collection of all items in the
pagefield. It finds which column the pagefield uses and loops through that
column adding unique entries to the collection. There's not a lot in the
way of error checking in it, but it should give you a start.

Function UniquePageFields(pt As PivotTable) As Collection

Dim colUniques As Collection
Dim pf As PivotField
Dim lCol As Long
Dim rCell As Range
Dim rngSource As Range

Set pf = pt.PageFields(1)
Set rngSource = Range(Application.ConvertFormula(pt.SourceData, xlR1C1,
xlA1))

lCol = Application.WorksheetFunction.Match(pf.SourceName,
rngSource.Rows(1), False)

Set colUniques = New Collection

For Each rCell In rngSource.Columns(lCol).Cells
On Error Resume Next
colUniques.Add rCell.Text, rCell.Text
On Error GoTo 0
Next rCell

Set UniquePageFields = colUniques

End Function


Sub test()

Dim vItm As Variant
Dim colPages As Collection

Set colPages = UniquePageFields(Sheet1.PivotTables(1))

For Each vItm In colPages
Debug.Print colPages.Item(vItm)
Next vItm

End Sub




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
Print Pivot Table headers on pages with Pivot Table tsgoose Excel Worksheet Functions 0 December 9th 08 08:14 PM
Filter lines with Pivot table and non pivot table columns Grover Charts and Charting in Excel 4 September 28th 07 03:16 AM
Filter lines with Pivot table and non Pivot table columns Grover Excel Discussion (Misc queries) 1 September 26th 07 12:48 AM
Help required with setting up a pivot table with the source on sheet1 to have the pivot table created on sheet called "report" Diana[_5_] Excel Programming 0 August 21st 03 10:19 PM


All times are GMT +1. The time now is 03:32 AM.

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"