Macro to Create Pivot Table

Johnny Firefly

New Member
Joined
Aug 19, 2010
Messages
3
Help!!! My first post on the forum. Have been tearing my hair out all afternoon trying to write this macro. My code is as follows:

Sub Macro1()
'Define where Pivot Table will be located
Range("A4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(3, 0).Activate

Dim PivotStart
PivotStart = ActiveCell.Address

'Define Pivot Source Data
ActiveSheet.Range("a4").CurrentRegion.Select

Dim PivotData As Range

Set PivotData = Selection

'Create Pivot Cache
Dim PC As PivotCache

PC = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PivotData)

'Create PivotTable
Dim PT As PivotTable

PT = PC.CreatePivotTable(PivotStart)
End Sub

The code highlighted in orange causes the following error:

I'm getting the following error:
Run-Time error '438':
Object doesn't support this property or method

Any guidance would be greatly appreciated
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Watch MrExcel Video

Forum statistics

Threads
1,122,421
Messages
5,596,033
Members
414,039
Latest member
southike

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
Top