PC Review


Reply
Thread Tools Rate Thread

assign filter inside macro

 
 
Atiq
Guest
Posts: n/a
 
      4th Aug 2008
hi there,

I am not a VBA user and got code from a book to generate a pivottable from a
macro. Now the problem is I want to assing the filter on column header '
Period' in the code and don’t know which property to change. following is the
code of the macro

Sub CreatePivotFields()

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:="'Source'!R1C1:R73C7", _
TableName:="Sales&Trans"

With ActiveSheet.PivotTables("Sales&Trans")
..PivotFields("Year").Orientation = xlPageField
..PivotFields("Year").Position = 1
..
..
..PivotFields("Period").Orientation = xlColumnField

at this point i want to assign a filter to 'Period' so it only display
period 'one' items in the pivot.

thanks,


 
Reply With Quote
 
 
 
 
Skinman
Guest
Posts: n/a
 
      5th Aug 2008
Try
I don't know how many items you have, you may have to adjust.

..PivotFields("Period").Orientation = xlColumnField
With ActiveSheet.PivotTables("Sales&Trans").PivotFields("Period")
.PivotItems("1").Visible = True
.PivotItems("2").Visible = False
.PivotItems("3").Visible = False
.PivotItems("5").Visible = False
End With
Skinman

"Atiq" <(E-Mail Removed)> wrote in message
news:F2C13BAE-F5B7-4F4D-A470-(E-Mail Removed)...
> hi there,
>
> I am not a VBA user and got code from a book to generate a pivottable from
> a
> macro. Now the problem is I want to assing the filter on column header '
> Period' in the code and don’t know which property to change. following
> is the
> code of the macro
>
> Sub CreatePivotFields()
>
> ActiveSheet.PivotTableWizard _
> SourceType:=xlDatabase, _
> SourceData:="'Source'!R1C1:R73C7", _
> TableName:="Sales&Trans"
>
> With ActiveSheet.PivotTables("Sales&Trans")
> .PivotFields("Year").Orientation = xlPageField
> .PivotFields("Year").Position = 1
> .
> .
> .PivotFields("Period").Orientation = xlColumnField
>
> at this point i want to assign a filter to 'Period' so it only display
> period 'one' items in the pivot.
>
> thanks,
>
>


 
Reply With Quote
 
Atiq
Guest
Posts: n/a
 
      5th Aug 2008
thanks Skinman, it worked.

now another question , is it possible to give excluesive code, i mean can
i put code to say that show "1" and hide all others without needing to know
the complete list of values in that pivot item.

thanks again.

"Skinman" wrote:

> Try
> I don't know how many items you have, you may have to adjust.
>
> ..PivotFields("Period").Orientation = xlColumnField
> With ActiveSheet.PivotTables("Sales&Trans").PivotFields("Period")
> .PivotItems("1").Visible = True
> .PivotItems("2").Visible = False
> .PivotItems("3").Visible = False
> .PivotItems("5").Visible = False
> End With
> Skinman
>
> "Atiq" <(E-Mail Removed)> wrote in message
> news:F2C13BAE-F5B7-4F4D-A470-(E-Mail Removed)...
> > hi there,
> >
> > I am not a VBA user and got code from a book to generate a pivottable from
> > a
> > macro. Now the problem is I want to assing the filter on column header '
> > Period' in the code and don’t know which property to change. following
> > is the
> > code of the macro
> >
> > Sub CreatePivotFields()
> >
> > ActiveSheet.PivotTableWizard _
> > SourceType:=xlDatabase, _
> > SourceData:="'Source'!R1C1:R73C7", _
> > TableName:="Sales&Trans"
> >
> > With ActiveSheet.PivotTables("Sales&Trans")
> > .PivotFields("Year").Orientation = xlPageField
> > .PivotFields("Year").Position = 1
> > .
> > .
> > .PivotFields("Period").Orientation = xlColumnField
> >
> > at this point i want to assign a filter to 'Period' so it only display
> > period 'one' items in the pivot.
> >
> > thanks,
> >
> >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Pens are tricky, hard to assign (Colors too) inside of paint handler Ben Voigt [C++ MVP] Microsoft C# .NET 2 3rd Sep 2008 02:56 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Microsoft Excel Worksheet Functions 2 10th Sep 2006 05:32 AM
using a cell value to control a counter inside a macro and displaying macro value ocset Microsoft Excel Worksheet Functions 0 9th Sep 2006 12:36 AM
assign form filter =?Utf-8?B?V2VuZHk=?= Microsoft Access Form Coding 2 18th Feb 2005 02:41 PM
Assign ID to a radiobutton inside a checkbox Abhishek Srivastava Microsoft ASP .NET 2 2nd Mar 2004 06:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 PM.