3
我在Excel中使用VBA創建報表。但是,當我嘗試創建一個數據透視表到一個特定的工作表時,它並沒有創建,它顯示一個錯誤「運行時錯誤'424'所需對象」。我在這裏發佈我的代碼,請告訴我是什麼問題在特定工作表中創建Excel 2010 VBA數據透視表不起作用
Private Sub CommandButton1_Click()
createPivot
End Sub
Sub createPivot()
' Creates a PivotTable report from the table on studentmarks
' by using the PivotTableWizard method with the PivotFields
' method to specify the fields in the PivotTable.
Dim objTable As PivotTable, objField As PivotField
' Select the sheet and first cell of the table that contains the data.
ActiveWorkbook.Sheets("studentmarks").Select
Range("A1").Select
Set objTable = reports.PivotTableWizard
''''Set objTable = Sheet1.PivotTableWizard // if I give sheet1 instead of reports it is working but every time it is creating new worksheets
objTable.ColumnGrand = False
' Specify a page field.
Set objField = objTable.PivotFields("subject")
objField.Orientation = xlPageField
' Specify row and column fields.
Set objField = objTable.PivotFields("name")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("subject")
objField.Orientation = xlColumnField
Set objField = objTable.PivotFields("total")
objField.Orientation = xlDataField
End Sub
我需要在「報告」工作表 請幫我創建的數據透視表..