teatimecrumpet
Active Member
- Joined
- Jun 23, 2010
- Messages
- 307
Hey guys,
I've been following a book on how to create a pivot table using VBA.
The code in the book works fine and it's doing what it's supposed to be doing. But i don't understand how to change how the Datafields are displayed.
It's listing the datafields horizontally one on top of the other in One column.
I want to know how to get the datafields to appear in separate columns (in the datafield area)
Here is the book's code:
Sub CreatePivot2()
' Create pivot table at active cell
' Assumes that the source table is in sheet called Source
ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:="'Source'!R1C1:R145C7", _
TableName:="Sales&Trans2"
ActiveSheet.PivotTables("Sales&Trans2").AddFields _
RowFields:=Array("Store City", "Store Type"), _
ColumnFields:="Period", _
PageFields:="Year"
With ActiveSheet.PivotTables("Sales&Trans2")
With .PivotFields("Transactions")
.Orientation = xlDataField
.Position = 1
End With
With .PivotFields("Sales")
.Orientation = xlDataField
.Position = 2
End With
End With
End Sub
And here is what I'd like the Pivot table to look like instead:
http://www.mrexcel.com/articles/fill-pivot-blank-cells.php
Thanks,
Mike
I've been following a book on how to create a pivot table using VBA.
The code in the book works fine and it's doing what it's supposed to be doing. But i don't understand how to change how the Datafields are displayed.
It's listing the datafields horizontally one on top of the other in One column.
I want to know how to get the datafields to appear in separate columns (in the datafield area)
Here is the book's code:
Sub CreatePivot2()
' Create pivot table at active cell
' Assumes that the source table is in sheet called Source
ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:="'Source'!R1C1:R145C7", _
TableName:="Sales&Trans2"
ActiveSheet.PivotTables("Sales&Trans2").AddFields _
RowFields:=Array("Store City", "Store Type"), _
ColumnFields:="Period", _
PageFields:="Year"
With ActiveSheet.PivotTables("Sales&Trans2")
With .PivotFields("Transactions")
.Orientation = xlDataField
.Position = 1
End With
With .PivotFields("Sales")
.Orientation = xlDataField
.Position = 2
End With
End With
End Sub
And here is what I'd like the Pivot table to look like instead:
http://www.mrexcel.com/articles/fill-pivot-blank-cells.php
Thanks,
Mike