LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Can't change pivotfilter value1 parameter in code

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).Piv otFilters(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?
 
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
use function to change a string to function's parameter ViestaWu Excel Worksheet Functions 3 November 21st 07 12:42 PM
Excel NPV initial cost in value1 and first year return in value2? Johanna Excel Worksheet Functions 3 September 12th 06 11:12 PM
EXCEL: VBE code for a push-down stack (Date,Value1,.....) Joe Bailey[_2_] Excel Programming 3 September 4th 06 10:01 PM
scatter plots and "label" as ("X" value1, value2) shabnam Charts and Charting in Excel 3 April 11th 05 02:24 PM
How to dinamic cell that searches for "value1 & value2" in table. armindo Excel Discussion (Misc queries) 3 February 4th 05 10:59 PM


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

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

About Us

"It's about Microsoft Excel"