Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从另一工作表源更新另一工作表上的多个透视表_Vba_Excel_Runtime Error_Pivot Table - Fatal编程技术网

Vba 从另一工作表源更新另一工作表上的多个透视表

Vba 从另一工作表源更新另一工作表上的多个透视表,vba,excel,runtime-error,pivot-table,Vba,Excel,Runtime Error,Pivot Table,我有一个在另一个工作表(而不是工作簿)中的计划,并根据该数据更新了透视表 问题是。。。当我尝试使用下面的宏时,我得到一个 运行时错误“9”下标超出范围 另外,计划02-26每天都会根据日期变化 Sub Change_Pivot_Source() Dim pt As PivotTable For Each pt In ActiveWorkbook.Worksheets("Schedule 02-26").PivotTables pt.ChangePivotCache ActiveWorkboo

我有一个在另一个工作表(而不是工作簿)中的计划,并根据该数据更新了透视表

问题是。。。当我尝试使用下面的宏时,我得到一个

运行时错误“9”下标超出范围

另外,计划02-26每天都会根据日期变化

Sub Change_Pivot_Source()

Dim pt As PivotTable

For Each pt In ActiveWorkbook.Worksheets("Schedule 02-26").PivotTables
pt.ChangePivotCache ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:="Schedule!$A$1:$AK$1200")

Next pt

End Sub
容易解决

更新:无法在中断模式下执行代码

我将宏代码放在这个工作簿中

'This might be helpful, starting out on your pivot table sheet

 Sub PivotUpdate()

 Dim PivotSheet as string
 Dim Data As Range
 Dim lrow As Long
 Dim PivotCount As Long
 Dim i As Long

 PivotSheet = activesheet.name

 sheets("schedule").select

 'get the last row where your data is
 lrow = sheets("schedule").Range("A1").End(xlDown).Row

 Set Data = sheets("schedule").Range("A1:AK" & lrow & "")

 Sheets(PivotSheet).Select

  PivotCount = Sheets(PivotSheet).PivotTables.Count

 For i = 1 To PivotCount

     Sheets(PivotSheet).PivotTables(i).ChangePivotCache ActiveWorkbook. _
     PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Data, _
     Version:=xlPivotTableVersion12)

  'version12 is excel 2007

 Next i

 End Sub