Using Value of Cell to Filter Pivot Table - Need Help

wpa101835

New Member
Joined
Nov 3, 2014
Messages
2
I am trying to use date from a cell (text) to filter my pivot table and thought I understood well enough to complete it but can't seem to get it right. It is probably something simple but I can't find the solution to the problem and have tried different methods to make it work but nothing is working for me. Below is my latest attempt. What am I doing wrong with this?


Sub NewTry()

Dim Field As PivotField
Dim pt As PivotTable
Dim TopItem As String

Set pt = Worksheets("Trim Total").PivotTables("PivotTop10")
Set Field = pt.PivotFields("Material Description")
TopItem = Worksheets("FY17 YTD Pivot Tables").Range("A19").Value

' Used the following line to ensure that the TopItem value was caputured - it showed up as expected in the T91 cell as expected.
' Worksheets("Trim Total").Range("T91") = TopItem

With pt
' The clear filters line works as it clears any active filters in the pivot table.
Field.ClearAllFilters
' The next line creates:
' Run-time error '1004":
' Application-defined or object-defined error
Field.CurrentPage = TopItem

pt.RefreshTable
End With
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,

I can't see anything strange on your code. Are you sure the worksheet names and pivottable names are correct?
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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