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
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

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