Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Question Multiple items in a PivotTable filter linked to one cell

Good afternoon all,

I'm currently using the code below to enter a date into a cell (range name Date3) on a sheet which then updates the WE_Date filter on my PivotTable on another sheet.

However, I now need to be able to enter a date as usual but want the PivotTable to display the entered date PLUS the previous date (these are week ending dates, so I guess something that reads the cell date then adds another value to the filter which is 'cell date' -7).

Any ideas?


Current code:

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

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 Date)
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
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
Items in Report Filter of PivotTable not "checked" automatically shabutt New Users to Excel 4 April 29th 09 03:33 AM
Filter PivotTable dropdown items to match report filter Catherine D Excel Discussion (Misc queries) 1 August 16th 08 12:12 AM
PivotTable - show top items Epinn New Users to Excel 5 October 25th 06 10:07 PM
Print Pivottable - show all selected items in page filter Koen Excel Discussion (Misc queries) 0 June 19th 06 09:30 AM
PivotTable - calculated items? Peter Aitken Excel Discussion (Misc queries) 1 July 4th 05 05:50 PM


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

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

About Us

"It's about Microsoft Excel"