我想创建一个宏使用的代码在以下网站建立数据透视表:VBA,数据透视表向导方法
http://msdn.microsoft.com/en-us/library/office/hh243933.aspx
,但我一直得到
错误1004:“无法获得枢轴表的枢轴特性 CLASS“
关于re的任何建议在这个问题背后有什么解决办法?
这是我的代码:
Sub CreatePivot()
' Creates a PivotTable report from the table on Sheet1
' 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("Sheet1").Select
Range("A2").Select
' Create the PivotTable object based on the Employee data on Sheet1.
Set objTable = Sheet1.PivotTableWizard
' Specify row and column fields.
***Set objField = objTable.PivotFields("v1")*** ' <-- This where I get the Error
objField.Orientation = xlColumnField
Set objField = objTable.PivotFields("Temperature")
objField.Orientation = xlRowField
' Specify a data field with its summary
' function and format.
Set objField = objTable.PivotFields("clkui")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.NumberFormat = "$ #,##0"
' Specify a page field.
Set objField = objTable.PivotFields("db")
objField.Orientation = xlPageField
' Preview the new PivotTable report.
ActiveSheet.PrintPreview
' Prompt the user whether to delete the PivotTable.
Application.DisplayAlerts = False
If MsgBox("Delete the PivotTable?", vbYesNo) = vbYes Then
ActiveSheet.Delete
End If
Application.DisplayAlerts = True
End Sub
是在“Sheet1”中创建的'PivotTable'吗?或不 ? “数据透视表”的数据在哪里?哪张工作表?范围 ? –
no.the pivottable not created.the data is in sheet1 – ofir
尝试我的回答下面的代码 –