Filtering two Pivot Tables from a cell referencing a drop down result.

coops365

New Member
Joined
Jul 30, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm sure my title makes this sound more complicated than it is.

The facts are these...
  • I have a sheet with two pivot tables that reference different data sources.
  • I have a drop down that allows the user to select a country, this drives a vlookup that generates the two letter ISO code in cell G4.
  • I have a command button that I would like to then change the filter for both pivots to the code listed in G4
this is my (borrowed) code...

VBA Code:
Private Sub CommandButton1_Click()


Dim a As String
Dim pt As PivotTable
 
ThisWorkbook.Worksheets("Look-Up").Activate
a = Worksheets("Look-Up").Cells(4, 7).Value

For Each pt In ActiveSheet.PivotTables
With pt.PivotFields("ISO Code")
.ClearAllFilters
.CurrentPage = a

End With

Next

End Sub

It works once, then throws up a 'Run-time error '1004': Application-defined or object-defined error'

The beginning and end of my VBA experience consists of copy and pasting other peoples' code, so I've no idea where to start. Can anyone advise? Thanks in advance.
 

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.

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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