"Unable to set the CurrentPage property of the PivotField Class" 与枢轴 Table 过滤尝试
"Unable to set the CurrentPage property of the PivotField Class" with Pivot Table Filtering Attempt
所以这两天我一直在努力找出我做错了什么,我似乎无法克服这个错误。
错误是“无法设置 PivotField Class 的 CurrentPage 属性”
这是我的代码:
Sub FilterBasedOnCellValue()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim pt As PivotTable
Dim PFilter As String
Dim pf As PivotField
Dim filterValue As String
Dim leftp As String
Dim rightp As String
Set wb = Application.Workbooks("Activity Report (Automated WIP).xlsm")
Set ws = wb.Worksheets("Formulas")
Set pt = ActiveSheet.PivotTables("DailyActivity")
Set pf = pt.PivotFields("[Activity_RAW].[Column1].[Column1]")
Set rng = ws.Range("Filter")
leftp = "&["
rightp = "]"
PFilter = "[Activity_RAW].[Column1]." & leftp & rng & "T00:00:00" & rightp
With pf
.ClearAllFilters
.CurrentPage = PFilter
.RefreshTable
End With
End Sub
似乎导致它的行是“.CurrentPage = PFilter”行。
“Column1”筛选器位于数据透视表 table 的实际“筛选器”字段中。当我录制一个过滤它的宏时,它使用了CurrentPage,这就是我困惑的原因。
我的数据透视表 Table 是一个基于 OLAP 的数据透视表,所以我不确定我是否使用了正确的代码?
如有任何帮助,我们将不胜感激。
谢谢!
所以我找到了导致问题的原因!
我需要将“.CurrentPage”更改为“.CurrentPageName”
我会 post 在这里为可能 运行 遇到与我相同的问题的任何人!
Sub FilterBasedOnCellValue()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim pt As PivotTable
Dim PFilter As String
Dim pf As PivotField
Dim filterValue As String
Dim leftp As String
Dim rightp As String
Set wb = Application.Workbooks("Activity Report (Automated WIP).xlsm")
Set ws = wb.Worksheets("Formulas")
Set pt = ActiveSheet.PivotTables("DailyActivity")
Set pf = pt.PivotFields("[Activity_RAW].[Column1].[Column1]")
Set rng = ws.Range("Filter")
leftp = "&["
rightp = "]"
PFilter = "[Activity_RAW].[Column1]." & leftp & rng & "T00:00:00" & rightp
With pf
.ClearAllFilters
.CurrentPageName = PFilter
End With
pt.RefreshTable
End Sub
所以这两天我一直在努力找出我做错了什么,我似乎无法克服这个错误。
错误是“无法设置 PivotField Class 的 CurrentPage 属性”
这是我的代码:
Sub FilterBasedOnCellValue()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim pt As PivotTable
Dim PFilter As String
Dim pf As PivotField
Dim filterValue As String
Dim leftp As String
Dim rightp As String
Set wb = Application.Workbooks("Activity Report (Automated WIP).xlsm")
Set ws = wb.Worksheets("Formulas")
Set pt = ActiveSheet.PivotTables("DailyActivity")
Set pf = pt.PivotFields("[Activity_RAW].[Column1].[Column1]")
Set rng = ws.Range("Filter")
leftp = "&["
rightp = "]"
PFilter = "[Activity_RAW].[Column1]." & leftp & rng & "T00:00:00" & rightp
With pf
.ClearAllFilters
.CurrentPage = PFilter
.RefreshTable
End With
End Sub
似乎导致它的行是“.CurrentPage = PFilter”行。
“Column1”筛选器位于数据透视表 table 的实际“筛选器”字段中。当我录制一个过滤它的宏时,它使用了CurrentPage,这就是我困惑的原因。
我的数据透视表 Table 是一个基于 OLAP 的数据透视表,所以我不确定我是否使用了正确的代码?
如有任何帮助,我们将不胜感激。
谢谢!
所以我找到了导致问题的原因!
我需要将“.CurrentPage”更改为“.CurrentPageName”
我会 post 在这里为可能 运行 遇到与我相同的问题的任何人!
Sub FilterBasedOnCellValue()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim pt As PivotTable
Dim PFilter As String
Dim pf As PivotField
Dim filterValue As String
Dim leftp As String
Dim rightp As String
Set wb = Application.Workbooks("Activity Report (Automated WIP).xlsm")
Set ws = wb.Worksheets("Formulas")
Set pt = ActiveSheet.PivotTables("DailyActivity")
Set pf = pt.PivotFields("[Activity_RAW].[Column1].[Column1]")
Set rng = ws.Range("Filter")
leftp = "&["
rightp = "]"
PFilter = "[Activity_RAW].[Column1]." & leftp & rng & "T00:00:00" & rightp
With pf
.ClearAllFilters
.CurrentPageName = PFilter
End With
pt.RefreshTable
End Sub