Filter a Pivottable based on a value of a cell (formula) in another worksheet

Romera

New Member
Joined
May 12, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi!

To sketch the sheet: The homepage is created as a dashboard with a pivottable which should contain the Names if the column Weeknumber is equal to the current weeknumber. So, the data is stored on another worksheet than where the pivottable is shown. The data in the column Weeknumber is calculated based on data in another column called Date, so it's a formula.

I want to have 1 cell with the formula =WEEKNUMBER(TODAY()) as the filter value so that this pivottable updates automatically every week.

The code shown below is not working for me. Unfortunately, it gets stuck in the following line:
VBA Code:
 Set Field = pt.PivotFields("Weeknumber")

Code:
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

If Intersect(Target, Worksheets("Dashboard").Range("L22:L23")) Is Nothing Then Exit Sub

    'Set the Variables to be used
    Dim pt As PivotTable
    Dim Field As PivotField
    Dim NewCat As String
    
    'Amend to suit data
    Set pt = Worksheets("Dashboard").PivotTables("Pivottable1")
    Set Field = pt.PivotFields("Weeknumber")
    NewCat = Worksheets("Dashboard").Range("L22").Value
    
    'This updates and refreshes the PIVOT table
    With pt
    Field.ClearAllFilters
    Field.CurrentPage = NewCat
    pt.RefreshTable
    End With

End Sub

I hope someone can help me with this!

All the best,
Romera
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top