我想創建一個宏使用的代碼在以下網站建立數據透視表: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
嘗試我的回答下面的代碼 –