我無法找到我的運行時錯誤424的根本原因。我知道這是與一個缺失的對象有關,但我不確定哪裏或哪個對象甚至會在這種情況下。我的假設是與ActiveSheet有關,但我有點失落。Excel宏運行時錯誤424
Sub Macro1()
'
' Macro1 Macro
'
'
Sheets.Add
錯誤這裏就從這裏開始
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
ActiveSheet.Range("A1").CurrentRegion.Select, Version:= _
xlPivotTableVersion12).CreatePivotTable TableDestination:="Sheet1!R3C1", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12
錯誤結束
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Source Type")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Category")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Category").Orientation = _
xlHidden
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Activity")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables(_
"PivotTable1").PivotFields("USD Amount"), "Sum of USD Amount", xlSum
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables(_
"PivotTable1").PivotFields("Quantity"), "Sum of Quantity", xlSum
End Sub