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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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