Writing Code for creating pivot table

kw42chan

New Member
Joined
Feb 4, 2011
Messages
15
Dear all,

I wrote the code in creating pivot table for my source of data.
However, when run the code, it prompts with the message. (I use Excel 2000)

"Run-time error '438':
Object doesnt support this property or method"

Below please find the code also.

****************************
Sub CreatePivotTable()

Dim PTCache As PivotCache
Dim PT As PivotTable

Application.ScreenUpdating = False

'Add a new sheet for the pivot table
Worksheets.Add

'Create the cache
Set PTCache =
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
SourceData:=Range("A1").CurrentRegion.Address)

'Create the pivot table
Set PT = ActiveSheet.PivotTables.Add(PivotCache:=PTCache,
TableDestination:=Range("A3"))

'Specify the fields
With PT
.PivotFields("street").Orientation = xlColumnField
.PivotFields("condition_code").Orientation = xlColumnField
.PivotFields("customer_code").Orientation = xlRowField
.PivotFields("liner_code").Orientation = xlRowField
.PivotFields("cont_type_code").Orientation = xlRowField
.DisplayFieldCaptions = False
End With

Application.ScreenUpdating = True

End Sub
****************************

Thanks in advance!!

kw42Chan
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,222,046
Messages
6,163,588
Members
451,846
Latest member
ajk99

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