【发布时间】:2014-10-22 06:30:43
【问题描述】:
我在 Excel 中使用 VBA 创建报告。但是,当我尝试为特定工作表创建数据透视表时,它没有创建并且显示错误“需要运行时错误'424'对象”。我在这里发布了我的代码,请告诉我有什么问题
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
我需要在“报告”工作表中创建数据透视表 请帮帮我..
【问题讨论】: