PC Review


Reply
Thread Tools Rate Thread

Changing multiple PivotTable filter items based on a cell value

 
 
New Member
Join Date: Jun 2010
Posts: 1
 
      15th Jun 2010
Good morning,

I have an Excel 2007 workbook containing 2 sheets, Sheet1 contains 2 pivots linked to an Access database, Sheet2 contains references to those 2 pivots to create a Summary.

What I'm looking to do is have a cell on the Summary sheet in which i can type a week ending date, i then want the 2 pivots to be filitered to this date AND the previous week.

For example, i type 09/05/2010 in the cell, both pivots update to show data for WE 09/05/2010 and WE 02/05/2010.

I've found the code below which seems to work but will only update the pivots to the value in the cell, I can't see how to make it select a second value (my VBA skills are very basic).

If anyone can help i'll be your freiend for life!

Current code im using:

Const RegionRangeName As String = "Date3"
Const PivotTableName As String = "PivotTable3"
Const PivotFieldName As String = "WE_Date"

Public Sub UpdatePivotFieldFromRange(RangeName As String, FieldName As String, _
PivotTableName As String)
Dim rng As Range
Set rng = Application.Range("Date3")

Dim pt As PivotTable
Dim Sheet As Worksheet
For Each Sheet In Application.ActiveWorkbook.Worksheets
On Error Resume Next
Set pt = Sheet.PivotTables("PivotTable3")
Next
If pt Is Nothing Then GoTo Ex

On Error GoTo Ex

pt.ManualUpdate = True
Application.EnableEvents = False
Application.ScreenUpdating = False

Dim Field As PivotField
Set Field = pt.PivotFields("WE_Date")
Field.ClearAllFilters
Field.EnableItemSelection = True
SelectPivotItem Field, rng.Text
pt.RefreshTable

Ex:
pt.ManualUpdate = False
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

Public Sub SelectPivotItem(Field As PivotField, ItemName As String)
Dim Item As PivotItem
For Each Item In Field.PivotItems
Item.Visible = (Item.Caption = ItemName)
Next
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(Target, Application.Range(RegionRangeName)) _
Is Nothing Then
UpdatePivotFieldFromRange _
RegionRangeName, PivotFieldName, PivotTableName
End If
End Sub
 
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
how do i update filter in a pivottable based on a cellvalue? Michael Murphy Microsoft Excel Misc 0 8th Feb 2010 03:05 PM
How to show data based on pivottable filter? Manny Microsoft Excel Misc 2 24th Jun 2009 05:58 PM
Filter PivotTable dropdown items to match report filter Catherine D Microsoft Excel Misc 1 16th Aug 2008 12:12 AM
Print Pivottable - show all selected items in page filter =?Utf-8?B?S29lbg==?= Microsoft Excel Misc 0 19th Jun 2006 09:30 AM
Formula based on row Items in Pivottable =?Utf-8?B?RGF2aWQgSg==?= Microsoft Excel Misc 1 31st Mar 2004 01:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:05 PM.