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