VBA filter Dates in pivottables

TomDK

New Member
Joined
Jan 22, 2017
Messages
1
Having a pivot table, I need to apply a filter with 1) a specific date and 2) data sets without a date.
I have tried the makro but it stops at " .PivotItems(i).Visible = False" in the first loop where i=1

Sub YesterdayBlank()
ActiveSheet.PivotTables("PivotTable2").ClearAllFilters
Dim yesterday As Date
yesterday = ActiveSheet.Range("F1").Value
Dim taeller As String
taeller = ActiveSheet.PivotTables("PivotTable2").PivotFields("OrderDate").PivotItems.Count

With ActiveSheet.PivotTables("PivotTable2").PivotFields("OrderDate")


For i = 1 To taeller
If .PivotItems(i) <> ("blank") And .PivotItems(i) <> yesterday Then
.PivotItems(i).Visible = False
Else
.PivotItems(i).Visible = True
End If
Next i
End With
End Sub

Any suggestions?

TomDK
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,216,095
Messages
6,128,795
Members
449,468
Latest member
AGreen17

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