Pivot Tables VBA

kw42chan

New Member
Joined
Feb 4, 2011
Messages
15
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!!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

Try change this
SourceData:="=Sheet1!R1C1:R500C11")

to
SourceData:="Sheet1!R1C1:R500C11")

HTH

M.

 
Upvote 0
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!!

Thanks a lot, i have changed a bit now prompts another...seems related to error created by the obj.

Worksheets("Sheet1").Activate

'Runtime error '424':Object required.

Thisworksheets.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"
 
Upvote 0
SourceData:="Sheet1!R1C1:R500C11"

If the name of the sheet that contains your data is Sheet1

M.
 
Upvote 0
SourceData:="Sheet1!R1C1:R500C11"

If the name of the sheet that contains your data is Sheet1

M.

Hi M,

I have amended the code but it still doesnt work.

Worksheets("Sheet1").Activate

'Runtime error '424':Object required.
Thisworksheets.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"
 
Upvote 0
Hi M,

I have amended the code but it still doesnt work.

Worksheets("Sheet1").Activate

'Runtime error '424':Object required.
Thisworksheets.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"

It worked for me, but without this

Worksheets("Sheet1").Activate

And like your #1 erasing the =

ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"



M.
 
Upvote 0
It worked for me, but without this

Worksheets("Sheet1").Activate

And like your #1 erasing the =

ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, _
SourceData:="Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
TableName:="ItemList"



M.
My excel ver is 2000, seems doesnt work. However, thanks for your information.:)
 
Upvote 0

Forum statistics

Threads
1,224,589
Messages
6,179,744
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top