Using VBA to update a Pivot Table filter based on the value in a cell

RPC1111

New Member
Joined
Sep 25, 2013
Messages
2
Hello,

I have a workbook with a tab (Individual) containing a cell (PT_Individual_ID), that is a specific customer ID, and 2 pivot tables which read a database contained in the second tab of the workbook. I want to be able to enter the customer ID and have the filters on the pivot tables update to filter based on the customer ID entered. Here's what I have so far - I get an error when it reaches the final step - any suggestions?

Sub auto_open()
ThisWorkbook.Worksheets("Individual").OnEntry = "INDV_ID"
End Sub

Sub INDV_ID()
Dim KeyCells As String
'Define which cells should trigger the KeyCellsChanged macro
KeyCells = "PT_Individual_ID"
'If the Activecell is one of the key cells, call the KeyCellsChanged macro
If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
Is Nothing Then KeyCellsChanged
End Sub

Sub KeyCellsChanged()
Sheets("Individual").PivotTables("PivotTable1").PivotFields("CUST_ID_NUM").ClearAllFilters
Sheets("Individual").PivotTables("PivotTable1").PivotFields("CUST_ID_NUM").CurrentPage _
= Worksheets("Individual").Range("PT_Individual_ID").Value

Sheets("Individual").PivotTables("PivotTable2").PivotFields("CUST_ID_NUM").ClearAllFilters
Sheets("Individual").PivotTables("PivotTable2").PivotFields("CUST_ID_NUM").CurrentPage _
= Range("PT_Individual_ID").Value


End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I have exactly the same problem. When the code riches the sentence where we put the new CurrentPage i have the following error: Run-time error '1004': Unable to set the Value property of the PivotItem class. I have Excel 2007.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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