提问人:Govinda Rathi 提问时间:10/7/2023 最后编辑:JohnMGovinda Rathi 更新时间:10/7/2023 访问量:27
使用 VBA 获取运行时错误的数据透视缓存
pivot cache using vba getting run time error
问:
我创建了一个脚本,该脚本在我的笔记本电脑上运行良好,但是当我的同事尝试使用相同的脚本时,透视缓存出现错误
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=1, SourceData:=range("A1:AV" & LastRow))
Sub pivot_qty()
Dim PCache As PivotCache, LastRow As Long, pt As PivotTable
'If "Pivot" worksheet already exists, delete it
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Pivot qty").Delete
On Error GoTo 0
Application.DisplayAlerts = True
LastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
Worksheets("Sheet1").Activate
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=1, SourceData:=range("A1:AV" & LastRow))
Worksheets.Add
ActiveSheet.Name = "Pivot qty"
Set pt = ActiveSheet.PivotTables.Add(PivotCache:=PCache, TableDestination:=range("A1"), TableName:="PivotTable1")
'Select fields for PivotTable
ActiveWorkbook.ShowPivotTableFieldList = True
With pt.PivotFields("Plant")
.Orientation = xlRowField
.Position = 1
End With
With pt.PivotFields("Service Desc")
.Orientation = xlRowField
.Position = 2
End With
With pt.PivotFields("Price Per Unit")
.Orientation = xlRowField
.Position = 3
End With
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub
答: 暂无答案
评论
Range