Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Naz Naz is offline
external usenet poster
 
Posts: 85
Default Pivot Table Field

Hi All,

I have a spreadsheet that contains sales by sales rep. Its very simple, I
have the sales rep name and the total sales for the year, which is a simple
sumif from a data list.
But what I want is to create a macro where you select the sales rep ID and
click a button and a pivot table opens in a new workbook showing the sales by
period (months). I'm almost there the only problem I can not figure out is
how to set the pivot table field to show only the information for the
selected sales rep. I have tried recording a macro to see how to do it but
all I get is this

Sub Macro1()

With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Employee")
.PivotItems("Ian Smith").Visible = False
.PivotItems("John Smith").Visible = False
.PivotItems("Nat Li").Visible = False
.PivotItems("Vivien Soul").Visible = False
End With

End Sub

With the one I have picked not in the list hence the property would be
visible=true.
Is there any way I can get the macro to say hide all except the chosen one,
as the list of sales reps constanty changes.


All help is greatly appreciated

Naz






--

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

Assuming this is a page field, you could use code similar to the following:

'=========================
Sub PivotOneEmp()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim strEmp As String

Application.ScreenUpdating = False

Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Employee")
strEmp = ActiveSheet.Range("F2").Value

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

pf.CurrentPage = strEmp

For Each pi In pf.PivotItems
If pi.Name = strEmp Then
pi.Visible = True
Else
pi.Visible = False
End If
Next pi

Application.ScreenUpdating = True

End Sub
'=====================

Naz wrote:
Hi All,

I have a spreadsheet that contains sales by sales rep. Its very simple, I
have the sales rep name and the total sales for the year, which is a simple
sumif from a data list.
But what I want is to create a macro where you select the sales rep ID and
click a button and a pivot table opens in a new workbook showing the sales by
period (months). I'm almost there the only problem I can not figure out is
how to set the pivot table field to show only the information for the
selected sales rep. I have tried recording a macro to see how to do it but
all I get is this

Sub Macro1()

With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Employee")
.PivotItems("Ian Smith").Visible = False
.PivotItems("John Smith").Visible = False
.PivotItems("Nat Li").Visible = False
.PivotItems("Vivien Soul").Visible = False
End With

End Sub

With the one I have picked not in the list hence the property would be
visible=true.
Is there any way I can get the macro to say hide all except the chosen one,
as the list of sales reps constanty changes.


All help is greatly appreciated

Naz








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

  #3   Report Post  
Posted to microsoft.public.excel.programming
Naz Naz is offline
external usenet poster
 
Posts: 85
Default Pivot Table Field

Many thanx

"Debra Dalgleish" wrote:

Assuming this is a page field, you could use code similar to the following:

'=========================
Sub PivotOneEmp()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim strEmp As String

Application.ScreenUpdating = False

Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Employee")
strEmp = ActiveSheet.Range("F2").Value

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

pf.CurrentPage = strEmp

For Each pi In pf.PivotItems
If pi.Name = strEmp Then
pi.Visible = True
Else
pi.Visible = False
End If
Next pi

Application.ScreenUpdating = True

End Sub
'=====================

Naz wrote:
Hi All,

I have a spreadsheet that contains sales by sales rep. Its very simple, I
have the sales rep name and the total sales for the year, which is a simple
sumif from a data list.
But what I want is to create a macro where you select the sales rep ID and
click a button and a pivot table opens in a new workbook showing the sales by
period (months). I'm almost there the only problem I can not figure out is
how to set the pivot table field to show only the information for the
selected sales rep. I have tried recording a macro to see how to do it but
all I get is this

Sub Macro1()

With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Employee")
.PivotItems("Ian Smith").Visible = False
.PivotItems("John Smith").Visible = False
.PivotItems("Nat Li").Visible = False
.PivotItems("Vivien Soul").Visible = False
End With

End Sub

With the one I have picked not in the list hence the property would be
visible=true.
Is there any way I can get the macro to say hide all except the chosen one,
as the list of sales reps constanty changes.


All help is greatly appreciated

Naz








--
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 do I remove a Calculated Field from the Pivot Table field list TheTraveler Excel Discussion (Misc queries) 2 April 9th 10 06:55 PM
Creating a Calculated Field in a Pivot Table for same field dza7 Excel Discussion (Misc queries) 3 October 21st 09 11:22 PM
sum a pivot table field as a calulated field Jerome Excel Discussion (Misc queries) 0 January 4th 08 02:24 PM
Pivit table- cell on spread sheet referencing pivot table field David M Charts and Charting in Excel 2 August 18th 07 07:46 PM
How to make a field created a part of the Pivot Table Field List? drhell Excel Discussion (Misc queries) 0 January 29th 07 11:13 PM


All times are GMT +1. The time now is 04:25 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"