PC Review


Reply
Thread Tools Rate Thread

Adding Report Filters to Excel Pivot Tables via VB.

 
 
Andreas Lundgren
Guest
Posts: n/a
 
      17th Oct 2011
Hi!

I'm writing my first VB script for Excel in order to generate nice
Pivot tables from loads of data.

When the Pivot table is generated, I want to add a "Report Filter" on
one parameter.

Straight forward macro after recording is the following; however, it
has a major problem:

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.PivotTables("PivotTable1").PivotFields("Result").CurrentPage
= "FAIL"

The problem occurs when the Pivot field "Result" doesn't contain any
item with the value "FAIL", this causes a runtime error. (Sometime the
data is all correct, believe it or not... ;-) )

Is there a way to first check if it contains any "FAIL" (and then only
set "CurrentPage" if it does)?

Best Regards,
Andreas
 
Reply With Quote
 
 
 
 
isabelle
Guest
Posts: n/a
 
      18th Oct 2011
hi Andreas,

With ActiveSheet.PivotTables(1).PivotFields("Result")
For Each pti In .PivotItems
If pti = "FAIL" Then .CurrentPage = "FAIL"
Next
End With


--
isabelle

 
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



Features
 

Advertising
 

Newsgroups
 


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