Set Pivot table filter from cell in another tab

Sophia_p

New Member
Joined
Aug 28, 2017
Messages
1
newbie at VBA

I have 2 sheets in my file- sheet1 "tab1" has a dropdown for customer(using a data validation list). this tab1 dropdown cell is named selection for ease in coding. On sheet2 - "tab2" I have pivot with customer as the pivot filter. I need to the set customer value from cell "selection" in tab1 as the pivot filter on tab2. Below is the code I'm using:


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
If Intersect(Target, Range("B3")) Is Nothing Then Exit Sub
 


Dim pt As PivotTable
Dim Field As PivotField
Dim sel As String
 


Set pt = Worksheets("tab2").PivotTables("PT")
Set Field = pt.PivotFields("customer")
'''''the below line shows a compile :object required error.
Set B3= Worksheets("Tab1").Range("selection").Value
 


With pt
Field.ClearAllFilters
Field.CurrentPage = sel
pt.RefreshTable
End With
 
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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