我有一个广泛的excel数据透视表的宏来创建6个数据透视表。每当我尝试运行宏时,我都会收到一个错误(5)、无效采购或参数。我浏览了各种论坛,但找不到修复此错误的方法。错误存在于第3-6行的某处。如果有人能给我指出正确的方向,我将不胜感激。我不精通VBA语言。
Range("A5").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"All Open Tool Records 05-22-20!R1C1:R4750C27", Version:= _
xlPivotTableVersion10).CreatePivotTable TableDestination:="Sheet1!R3C1", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Department")
.Orientation = xlRowField
.Position = 1
End With
发布于 2020-05-23 05:00:39
最好使用变量来捕获流程中的各种对象-这会使整个过程更易于管理:
Dim pc As PivotCache
Dim pt As PivotTable
dim ws As Worksheet
Set ws = Sheets.Add() 'assuming this is where the pivot table goes....
Set pc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:= "All Open Tool Records 05-22-20!R1C1:R4750C27", _
Version:= xlPivotTableVersion10)
Set pt = pc.CreatePivotTable(TableDestination:=ws.Range("A3"), _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10)
With pt.PivotFields("Department")
.Orientation = xlRowField
.Position = 1
End With
https://stackoverflow.com/questions/61963264
复制相似问题