Hi All
I've got a script which will create a pivot table and display the fields that I want.
Here is a sample code of what I have
Code
Dim WSD As Worksheet
Set WSD = Worksheets("SESSIONS PER USER - BY WEEK")
Dim finalRow As Long ' Find the last column with data
Dim finalCol As Long ' Find the range of the data
finalRow = WSD.Cells(Rows.Count, 1).End(xlUp).Row 'finalRow and finalCol, will give me the range of data the pivot table needs
finalCol = WSD.Cells(3, Columns.Count).End(xlToLeft).Column
'Creates the pivot table
'Creates the pivot table
Sheets.Add.Name = "Table2"
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"SESSIONS PER USER - BY WEEK – R!R3C1:R" & finalRow & "C" & finalCol, Version:=xlPivotTableVersion10 _
).CreatePivotTable TableDestination:="Table2!R3C1", TableName:= _
"PivotTable10", DefaultVersion:=xlPivotTableVersion10
Sheets("Table2").Select
'Selects the following fields to display
With ActiveSheet.PivotTables("PivotTable10").PivotFields("Page")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable10").PivotFields("Account")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable10").AddDataField ActiveSheet.PivotTables( _
"PivotTable10").PivotFields("Page Views"), "Sum of Page Views", xlSum
ActiveSheet.PivotTables("PivotTable10").PivotFields("Page").AutoSort _
xlDescending, "Sum of Page Views", ActiveSheet.PivotTables("PivotTable10"). _
PivotColumnAxis.PivotLines(1), 1
ActiveSheet.PivotTables("PivotTable10").PivotFields("Username").AutoSort _
xlDescending, "Sum of Page Views", ActiveSheet.PivotTables("PivotTable10"). _
PivotColumnAxis.PivotLines(1), 1
Display More
Now I need to make a new pivot table, see screenshot. It should display account, and a sum for each of the weeks. However the "weeks" are not static. I'm hoping that there is a way for VBA to select ALL of the fields except the field Account Type,Name and Sum
[ATTACH=CONFIG]43651[/ATTACH]