Filtering for 2 values in a PivotTable VBA

Tregs

New Member
Joined
Aug 31, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hello, I am very new to VBA. I am trying to update my processes for my morning reports. I have multiple pivot tables that need to be filtered to yesterday and a week prior to yesterday. I found out that .CurrentPage is only for one value, so I tried creating a loop with no luck. Please excuse my formatting and thank you in advance.

Dim sI As SlicerItem
Dim FD As Long 'yesterday fiscal date
Dim i As Long
Dim pT As PivotTable
Dim pF As PivotField

FD = ActiveSheet.Range("F1").Value

Application.ScreenUpdating = False
Application.EnableEvents = False


For Each pT In Worksheets("WoW").PivotTables
With pT.PivotFields("Fiscal_Date")
On Error Resume Next
For i = 2 To Field.PivotItems.Count
If .PivotItems(i).Value = FD Then
.PivotItems(i).Visible = True
ElseIf .PivotItems(i).Value = FD - 7 Then
.PivotItems(i).Visible = True
Else
.PivotItems(i).Visible = False
End If
Next i
End With
Next pT

Application.ScreenUpdating = True
Application.EnableEvents = True


End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,067
Messages
6,122,949
Members
449,095
Latest member
nmaske

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