0

I am creating a dashboard with multiple pivot tables and have run into a problem that I cant seem to overcome. I have a primary worksheet where all the data will be displayed with direct references to the pivots tables which reside on another worksheet. I am using a combobox to filter the data from the pivot tables. I have been able to get the VBA code working for the macro when I am on the worksheet containing the pivot tables, but I cant get it to work when I am on the primary page where the customer will actually choose the filter, as far as I can tell the issue resides with the .CurrentPage variable, I don't how I can change this to filter correctly. Below is the code I have, the combobox is on worksheet("Dashboard") while the PvtTbls are on Worksheet("Pivot Tables"). Can anyone guide me on how to get this working, I am tearing out my hair researching this the last 3 days with no luck.

Sub Year_Change()
'
' Year_Change Macro
'
    Worksheets("Pivot Tables").PivotTables("Termination Index").PivotFields("Year").CurrentPage = (Range("I1"))
    Worksheets("Pivot Tables").PivotTables("Quality Index Top").PivotFields("Year").CurrentPage = (Range("I1"))
End Sub

Thank you in advance for all of your help.

4

1 回答 1

0

我试图重现您的问题,CurrentPage 的“目标值”是一个单元格(即 Range("a1"))而不是一个组合框。添加“.value”对我有用。

Sub Year_Change()
Dim ws As Worksheet
    Worksheets("Pivot Tables").PivotTables("Pivottable1").PivotFields("Year").CurrentPage = (ActiveSheet.Range("A1").Value)
    Worksheets("Pivot Tables").PivotTables("Pivottable2").PivotFields("Year").CurrentPage = (ActiveSheet.Range("A1").Value)
End Sub

对于您的问题:您能否详细说明您正在使用的组合框?它是适当的 activeX 控件还是只是单元格中允许数据的过滤器?

于 2013-06-26T12:52:05.797 回答