Pivot Table Filter Button - VBA

Status
Not open for further replies.

joejs

New Member
Joined
Mar 22, 2019
Messages
6
I am working on VBA code in Excel to filter a pivot table (on a different sheet with a different data source) based on the selection on a different pivot table using a button.

I have gone on multiple forums and altered code to my needs but I have been unsuccessful in connecting the code to my needs. I have tried code such as objects and modules for changing pivot table filters and refreshing. I am currently working on building my code from scratch but I have hit a road block. Anything helps! Thanks

I expect to be able to select "Style" in one pivot table and then have that selection populate the other pivot table once I click on the button. Right now there is no error but the fields are not updating. I was wondering if anyone knows how to filter a pivot table on a different sheet with different source data based on another pivot table using VBA?



<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Option Explicit


Sub Button1_Click()

Dim ws As Worksheet, ws2 As Worksheet
Dim pvtTable As PivotTable, pvtTable2 As PivotTable
Dim pvtField As PivotField, pvtField2 As PivotField
Dim pvtItem As PivotItem, pvtItem2 As PivotItem
Dim s$, a$

'ws.pvtTable.PvtField
Set ws = ActiveSheet
Set pvtTable = ws.PivotTables("PivotTable1")
Set pvtField = pvtTable.PivotFields("Style")

'ws2.pvtTable2.pvtField2
Set ws2 = Sheets(2)
Set pvtTable2 = ws2.PivotTables("PivotTable2")
Set pvtField2 = pvtTable2.PivotFields("Style")

'Setting the filters - issues here?
'Let s = ws.PivotTables("PivotTable1").pvtField
Let s = pvtField
'Let a = ws2.PivotTables("PivotTable2").pvtField2
Let a = pvtField2
Let a = s

EndSub

</code>
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Duplicate https://www.mrexcel.com/forum/excel...pivot-tables-vba-post5247449.html#post5247449

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

If you do not receive a response, you can "bump" it by replying to it again, though we advise you to wait 24 hours before doing and not to bump a thread more than once a day.


 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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