Hi all,
I m a newbie in using VBA and now I come across creating pivot table.
Here is the code but it said there is runtime error 438:Object doesnt support this property or method.
Sub PivotTable()
Dim Pt As PivotTable
Dim strField1, strField2 As String
strField1 = Selection.Cells(1, 1).Text
strField2 = Selection.Cells(1, 2).Text
Worksheets("sheet1").Activate
'Runtime error 438:Object doesnt support this property or method.
ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="=Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"
'Set a Pivot Table variable to our new Pivot Table
Set Pt = ActiveSheet.PivotTables("ItemList")
'Place the Pivot Table to Start from A3 on the new sheet
ActiveSheet.PivotTableWizard TableDestination:=Cells(1, 1)
'Move the list heading to the Row Field
'Pt.AddFields RowFields:=strField1, strField2
'Pt.AddFields RowFields:
'Move the list heading to the Data Field
'Pt.PivotFields(strField).Orientation = xlDataField
With Pt
.SmallGrid = False
.AddFields RowFields:=Array("customer_code", "liner_code"), ColumnFields:=Array("condition_code")
.PivotFields("in_date").Orientation = xlDataField
'.Format xlReport6
End With
End Sub
Could anyone plot the error? Thanks a lot!!
I m a newbie in using VBA and now I come across creating pivot table.
Here is the code but it said there is runtime error 438:Object doesnt support this property or method.
Sub PivotTable()
Dim Pt As PivotTable
Dim strField1, strField2 As String
strField1 = Selection.Cells(1, 1).Text
strField2 = Selection.Cells(1, 2).Text
Worksheets("sheet1").Activate
'Runtime error 438:Object doesnt support this property or method.
ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="=Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"
'Set a Pivot Table variable to our new Pivot Table
Set Pt = ActiveSheet.PivotTables("ItemList")
'Place the Pivot Table to Start from A3 on the new sheet
ActiveSheet.PivotTableWizard TableDestination:=Cells(1, 1)
'Move the list heading to the Row Field
'Pt.AddFields RowFields:=strField1, strField2
'Pt.AddFields RowFields:
'Move the list heading to the Data Field
'Pt.PivotFields(strField).Orientation = xlDataField
With Pt
.SmallGrid = False
.AddFields RowFields:=Array("customer_code", "liner_code"), ColumnFields:=Array("condition_code")
.PivotFields("in_date").Orientation = xlDataField
'.Format xlReport6
End With
End Sub
Could anyone plot the error? Thanks a lot!!