Linking pivot filter to cell

Siggi

New Member
Joined
Apr 27, 2018
Messages
5
Hello,

the topic was already discussed in a different thread, however it rather seems dead and I did not receive any further feedback.
In the thread it was discussed to connect a cell within separate worksheet to a pivot table. The formula from the thread (below) works very well, however I want to include more than on filter that connect to different cells, for example I have a filter value in B2 and B3 and responds to MyReportField1 and the other one to ReportField2. I'm not really sure, where I can include that in the code below.

I would be very happy if someone could help out with that.

Thanks and best regards,
S.

Code:
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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
After a long search on older posts I came to a simple solution. I found that many were interested in the topic, but when it came to change several filters based on different values most of the threads stopped. The solution is however not a worksheet_change procedure, but embedded in a macro and came from AlphaFrog
https://www.mrexcel.com/forum/excel...-cell-data-filter-pivot-table-date-field.html
It's simple as that:
Code:
[COLOR=darkblue]Sub[/COLOR] Apply_Reporting_Group_Filter()

    [COLOR=darkblue]With[/COLOR] Worksheets("Sheet1").PivotTables("Campaigns")
        .PivotFields("Reporting Group").CurrentPage = Worksheets("Data Control").Range("A1").Value
        .PivotFields("Reporting Date").CurrentPage = Worksheets("Data Control").Range("B1").Value
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]

[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub
[/COLOR]


I hope that helps other peoples searching for a solution.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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