Pivot Tables using the Macro recorder but with a variable range

Sambr

New Member
Joined
Jul 11, 2011
Messages
1
Hi, I am trying to create a pivot table using the macro recorder, but it seems that when my range increases the extra rows in my pivot table are not included.
Any ideas how i can solve this?


Many thanks,
Sam


Here is my code

Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Part 5 Pivot Source!R1C1:R3868C34", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="Sheet8!R3C1", TableName:="PivotTable3" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("Sheet8").Select
Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.pIVOTtABLES("PivotTable3").PivotFields("Customer_id")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.pIVOTtABLES("PivotTable3").AddDataField ActiveSheet.pIVOTtABLES( _
"PivotTable3").PivotFields("Total Passengers"), "Sum of Total Passengers", _
xlSum
With ActiveSheet.pIVOTtABLES("PivotTable3").PivotFields("Country")
.Orientation = xlRowField
.Position = 2
End With
Range("D3").Select
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

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