I'm just getting in to pivot tables, so in my attempt to control them with VBA I recorded my self making a pivot table to count the occurrences of an item. I based what I was trying to do off of this youtube video: http://www.youtube.com/watch?v=OlTsegp3cDY
In short, I have a table like this:
Items Months Bananas May Apples June Banans July Bananas August Apples September Oranges November
It's on Sheet49, starting in R1C1. I recorded the following Macro while creating a PivotTable that includes the number of occurrences of each item. When I'm done, it looks like this:
Pivot1.PNG
However, when I delete the pivot table, and run the recorded Macro (see below):
All I get is this:![]()
Sub Pivot4() ' ' Pivot4 Macro ' ' ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ "Sheet49!R1C1:R7C1", Version:=xlPivotTableVersion10).CreatePivotTable _ TableDestination:="Sheet49!R1C4", TableName:="PivotTable6", DefaultVersion _ :=xlPivotTableVersion10 Sheets("Sheet49").Select Cells(1, 4).Select With ActiveSheet.PivotTables("PivotTable6").PivotFields("Items") .Orientation = xlRowField .Position = 1 End With ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _ "PivotTable6").PivotFields("Items"), "Count of Items", xlCount End Sub
Pivot2.PNG
I loose all the data in the PivotTable and only get the total number of items!
What is going on?
Thanks for any help!
Bookmarks