Hi,
I need support in creating pivot with a code base, below is the code that i am using to create pivot. It works perfectly as expected for one parameter for row field or column field etc. But now i need to create a pivot with multiple row fields and column fields and data fields.
If anyone can support on how to pass arguments for multiple values for one parameter, it would be of great help
Thanks
Raj
Sub MakePivotCriteria(SourceSheetName As String, SourceTableName As String, RowField As String, ColField As String, DataField As String, PageField As String)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SourceTableName).CreatePivotTable _
TableDestination:=Worksheets(SourceSheetName).Range("A1"), TableName:=SourceTableName
With ActiveSheet.PivotTables(SourceTableName).PivotFields(ColField)
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables(SourceTableName).PivotFields(RowField)
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables(SourceTableName).PivotFields(DataField)
.Orientation = xlDataField
.Position = 1
.Function = xlCount
.NumberFormat = "0"
End With
With ActiveSheet.PivotTables(SourceTableName).PivotFields(PageField)
.Orientation = xlPageField
.Position = 1
.EnableMultiplePageItems = True
End With
With Worksheets(SourceSheetName).PivotTables(SourceTableName)
.TableStyle2 = "PivotStyleDark5"
End With
End Sub