VBA Pivot Table help

Amy Beryl

Board Regular
Joined
May 5, 2011
Messages
54
I am trying to build a macro to create a pivot table from data in a spreadsheet. I am having trouble with one of the lines of code and I'm stumped. the line is the one below that is bolded. Any help would be appreciated.

Amy

Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range

' Define input area and set up a Pivot Table Cache
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
Set PRange = Cells(1, 1).Resize(finalrow, 4)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="PRange")


Set PT = PTCache.CreatePivotTable(TableDestination:=Cells(1, 6), TableName:="PivotTable1")
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try removing the double quotes from your SourceData:="PRange" -part:
Code:
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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