Excel Formula to Link Pivot Filter with a Cell

shansakhi

Active Member
Joined
Apr 5, 2008
Messages
276
Office Version
  1. 365
Platform
  1. Windows
Dear All,
Is there a way to link a cell to Pivot Filter with Excel Formula.
I have gone through the VBA but its clearing all the Filters which is not suitable for me as I do have few filters which I do not want to clear.
Hence requesting your expertise for excel formula which can control Pivot Table.

Regards,
Shan
 

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.
A formula cannot control a pivot table. (It can affect what is shown but only after refreshing the pivot table somehow) What is the VBA you have now and what is the issue with it specifically?
 
Last edited:
Upvote 0
Thank you for reply.
I have below VBA code which I took from this website. But in code I saw clear all filters line hence did not used that. I do not want to use clear filter option as it will clear all my filters set in pivot.

I have below set of data.
Sheet Name: Final (where I want to to type Value in a Cell which will be linked to pivot.
Sheet Name: Actuals (here two pivots are available with same data source)
Sheet Name: Budget (Here one pivot available with different data source)


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = Range("B2").Address Then Exit Sub
Dim PT As PivotTable
Dim ptItem As PivotItem
On Error Resume Next
For Each PT In Worksheets("Sheet1").PivotTables
With PT.PivotFields("MyReportField")
If .EnableMultiplePageItems = True Then
.ClearAllFilters
End If
Set ptItem = .PivotItems(Target.Value)
If Not ptItem Is Nothing Then
.CurrentPage = Target.Value
End If
End With
Next
End Sub
Regards
Shan
 
Upvote 0
That line only clears the filters on the specific field, not all the filters on the pivot table.
 
Upvote 0
Thank you. Sorry for late reply.
The macro is working fine for me. I have two more issue with this.

1.When I am removing value from cell Pivot filters remains constant on the last filtered value. I want the filter to be opened when value from cell is removed.

2. I have tried using same macro for different Pivot fields of same pivot but its not working. Do I need some changes in this.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = Range("S2").Address Then Exit Sub
Dim PT As PivotTable
Dim ptItem As PivotItem
On Error Resume Next
For Each PT In Worksheets("Actuals").PivotTables
With PT.PivotFields("Region")
If .EnableMultiplePageItems = True Then
.ClearAllFilters
End If
Set ptItem = .PivotItems(Target.Value)
If Not ptItem Is Nothing Then
.CurrentPage = Target.Value
End If
End With
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,132
Messages
6,123,227
Members
449,091
Latest member
jeremy_bp001

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