Filter a pivot based on date in a cell

laxminarayana

Board Regular
Joined
Nov 16, 2013
Messages
56
Hello,

My pivot table contains dates and product received. I am trying automate the filtering of date in pivot, so that when i enter a date in a desired cell, pivot would filter with the date in the cell and return the number. I have put up the following code to achieve this. But ended up with error as 'expected end of statement'. Please help me to fix the code.

Code:
Sub Macro1()Dim ws1 As Worksheet:   Set ws1 = Sheets("Sheet1")
ActiveSheet.PivotTables("PivotTable1").RefreshTable
ActiveSheet.PivotTables("PivotTable1").PivotFields("OrderDate").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable1").PivotFields("OrderDate").PivotFilters. _
        Add Type:=xlSpecificDate, Value1:="ws1.Range("F1").Value"
End With
End Sub

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Thank you.
I'm still unable to get this to work. As there seems to be difference in vba code when using 'Report Filter' and 'Row labels'.
I've placd my file in below link, as files cannot be attahed in post.
Inventory
Can you please have a look.
Thank you! for your time and information.
 
Upvote 0
Try:

Code:
Sub filtbycellv()
Dim Pi As PivotItem
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Date")
.PivotItems(Range("c1").Value).Visible = True
For Each Pi In .PivotItems
If Pi.Value = Range("c1").Value Then
Pi.Visible = True
Else
Pi.Visible = False
End If
Next Pi
End With
ActiveSheet.PivotTables("PivotTable1").RefreshTable
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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