0
我嘗試運行下面的代碼時出現錯誤。任何人都可以請解釋爲什麼當代碼嘗試創建數據透視表時,爲什麼在最後一部分出現錯誤?在VBA中創建數據透視表時出錯
錯誤說:「無效的過程調用或參數」當我設置PVT
Private Sub CommandButton1_Click()
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String
For Each PT In Sheet5.PivotTables
PT.TableRange2.Clear
Next PT
'Determine the data range you want to pivot
SrcData = ActiveSheet.Name & "!" & Range("B7:D10").Address(ReferenceStyle:=xlR1C1)
'Where do you want Pivot Table to start?
StartPvt = Sheet5.Name & "!" & Sheet5.Range("B12").Address(ReferenceStyle:=xlR1C1)
'Create Pivot Cache from Source Data
Set pvtCache = ActiveWorkbook.PivotCaches.Create(_
SourceType:=xlDatabase, _
SourceData:=SrcData)
MsgBox StartPvt & "_" & SrcData
'Create Pivot table from Pivot Cache
Set pvt = pvtCache.CreatePivotTable(_
TableDestination:=StartPvt, _
TableName:="TestPivotTable")
End Sub
錯誤發生的確切線是什麼?那錯誤信息是什麼意思? – rohrl77
錯誤說:「無效的過程調用或參數」在我設置pvt的最後部分。 –