PC Review


Reply
Thread Tools Rate Thread

Can't change pivotfilter value1 parameter in code

 
 
PeterF
Guest
Posts: n/a
 
      29th Nov 2008
I have a workbook that has a bunch of pivottables that are based on an
Analysis Services cube. Each of the pivottables has a filter on it that
limits the row data to one customer account. Once a week I go in an manually
change the filter for the "Account ID" field so that the pivottables show the
data in the pivots for a different account.

All works great, except it is manual so I took some time and tried to write
some VB code to automate the update for all pivots. To get started a
recorded a macro. The macro has the following code:
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Account].[Account ID].[Account ID]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Account].[Account ID].[Account ID]").PivotFilters.Add
Type:=xlCaptionEquals _
, Value1:="194108"

Here's what I don't understand, when I run the macro, I get an "Out of
Memory" error when it attempts to "ClearAllFields". So I removed that line
of code and I am just running the second line...
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Account].[Account ID].[Account ID]").PivotFilters.Add
Type:=xlCaptionEquals _
, Value1:="194108"

The thing is, when I run this line by itself, I get an error:
"Run-time error '1004':
Application-defined or object-defined error"

Why am I able to do this manually, when I recorded the macro, but not when
run it through code? My guess is that it doesn't let me "add" a filter to
something that already has the filter (hence the "ClearAllFilters" that the
recorded macro had). Is there a workaround where I could just change the
filter value? I tried just setting the value1 parameter (which says is
read/write) with the following:

Worksheets("Major App Usage over 30
days").PivotTables("Pivottable1").RowFields(1).PivotFilters(1).Value1 =
"132238"

But that didn't work because I got a "Wrong number of arguments or invalid
property assignment".

Any ideas for a workaround?
 
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
using a String Builder a actual parameter and LPTSTR as formal parameter in unmanaged code Tony Johansson Microsoft C# .NET 1 30th Apr 2010 03:00 AM
Update Pivotfilter against Cell value Henrik Microsoft Excel Programming 4 21st Jun 2009 08:22 PM
My fields won't add toegther in Access (VALUE:([VALUE1]+[VALUE2]) =?Utf-8?B?Q2xhcmlz?= Microsoft Access Queries 4 5th Feb 2007 06:48 AM
EXCEL: VBE code for a push-down stack (Date,Value1,.....) =?Utf-8?B?Sm9lIEJhaWxleQ==?= Microsoft Excel Programming 3 4th Sep 2006 10:01 PM
Registry parameter to change OS Country Code? Didier Morandi Windows XP General 0 14th Nov 2005 07:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.