Excel 为什么我收到运行时错误5无效的过程调用或参数?
我在设置pivot缓存时收到错误。即在这一行:-Excel 为什么我收到运行时错误5无效的过程调用或参数?,excel,vba,Excel,Vba,我在设置pivot缓存时收到错误。即在这一行:- Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="PivotTable2") 我已在其他工作簿中使用此宏,但未收到此错误 Sub PivTable() ' ' Insert a pivot table ' Dim sht As Worksheet Dim pvtCache As PivotCache Dim pvt As PivotTabl
Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="PivotTable2")
我已在其他工作簿中使用此宏,但未收到此错误
Sub PivTable()
'
' Insert a pivot table
'
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String
Dim ws As Worksheet
Dim x As Long
Set ws = Worksheets("Cash Month End")
With ws
x = .Range("b999999").End(xlUp).Row
End With
'Data Range to pivot
SrcData = "Cash Month End!(R4C1:R" & x & "C24)"
' Insert Sheet
Sheets.Add.Name = "Cash Pivot"
'Where the pivot must start
StartPvt = "Cash Pivot!R3C1"
'Create the pivot cache
Set pvtCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SrcData)
'Create Pivot Table from Pivot Cache
Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="PivotTable2")
'Add fields
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Segment")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Region")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("No."), "Sum of No", xlSum
End Sub
您的选项卡名称中有一个空格,因此可能需要一些单引号a(假设它正在单元格中的公式中使用)
StartPvt=“'Cash Pivot'!R3C1”
Se this:@JNevill谢谢!