我正在通过不同工作表中的单元格引用更新 Powerpivot 数据透视表,但无法确定正确的语法。
如果我对日期进行硬编码(见下文),该代码就可以正常工作:
Sheets("Close Rate").Select 'Select the sheet containing the pivot table to update
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Closed Cases].[Closed Date Week End].[Closed Date Week End]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Closed Cases].[Closed Date Week End].[Closed Date Week End]"). _
CurrentPageName = _
"[Closed Cases].[Closed Date Week End].&[2013-09-28T00:00:00]"
但是,如果我尝试使用变量而不是硬编码日期,则会收到“应用程序定义或对象定义错误”消息。
这是我正在尝试使用的代码:
'Set up variables
Dim FilterDate As String
FilterDate = Sheets("CS Dashboard").Range("I5").Value 'Get date for filter
Sheets("Close Rate").Select 'Select the sheet containing the pivot table to update
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Closed Cases].[Closed Date Week End].[Closed Date Week End]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Closed Cases].[Closed Date Week End].[Closed Date Week End]"). _
CurrentPageName = _
"[Closed Cases].[Closed Date Week End].&[FilterDate]"
任何人都可以就我应该如何编码以便它使用变量提供一些指导吗?