Hi,
I am trying to use VBA to filter a pivot table value (Top 10 etc) based on a cell value on a seperate sheet.
1. Not sure if I reference Set pvtField = pvtTable.PivotFields("Employer_Name") or Set pvtField = pvtTable.PivotFields("Sum of Value")
2. The command filter (For Each pvtItem In pvtField.PivotItems _
pvtFields.xlTopCount _ pvtFields.Value = filterVal _ Next pvtItem) is causing me a headache.
Is this possible to do? Any help greatly appreciated.
Sub Top_Filter_1()
Dim pvtTable As PivotTable
Dim pvtField As PivotField
Dim pvtItem As PivotItem
Dim filterVal As String
Set pvtTable = Worksheets("T RM LW").PivotTables("PivotTable6")
Set pvtField = pvtTable.PivotFields("Employer_Name")
filterVal = Worksheets("Data").Range("C3")
For Each pvtItem In pvtField.PivotItems
pvtFields.xlTopCount
pvtFields.Value = filterVal
Next pvtItem
End Sub
I am trying to use VBA to filter a pivot table value (Top 10 etc) based on a cell value on a seperate sheet.
1. Not sure if I reference Set pvtField = pvtTable.PivotFields("Employer_Name") or Set pvtField = pvtTable.PivotFields("Sum of Value")
2. The command filter (For Each pvtItem In pvtField.PivotItems _
pvtFields.xlTopCount _ pvtFields.Value = filterVal _ Next pvtItem) is causing me a headache.
Is this possible to do? Any help greatly appreciated.
Sub Top_Filter_1()
Dim pvtTable As PivotTable
Dim pvtField As PivotField
Dim pvtItem As PivotItem
Dim filterVal As String
Set pvtTable = Worksheets("T RM LW").PivotTables("PivotTable6")
Set pvtField = pvtTable.PivotFields("Employer_Name")
filterVal = Worksheets("Data").Range("C3")
For Each pvtItem In pvtField.PivotItems
pvtFields.xlTopCount
pvtFields.Value = filterVal
Next pvtItem
End Sub