K
kansaskannan
I created a VBA function to generate a number of pivot tables. For
each pivot table required, I supply 12 arguments used by the function.
For some pivot tables, however, I do not need a page field. How do I
make this pagefield optional? I give the code below. 'pfd' is the
pagefield which I want to make optional.
Thank you!
===============================================================
Public Function CreatePvt(snm, ptn, rfd, cfd, dfd, fun, cal, nft, cap,
pos, stl, pfd)
Set pt = _
PC.CreatePivotTable(TableDestination:=ActiveSheet.Cells(dr + 5, 1),
TableName:=ptn)
'-------------add row column and page fields
pt.AddFields RowFields:=rfd, ColumnFields:=Array(cfd), PageFields:=pfd
'-------------add data fields
With pt.PivotFields(dfd)
.Orientation = xlDataField
.Function = fun
.Caption = cap
.Calculation = cal
.Position = pos
.NumberFormat = nft
End With
Set pt = Nothing
End Function
each pivot table required, I supply 12 arguments used by the function.
For some pivot tables, however, I do not need a page field. How do I
make this pagefield optional? I give the code below. 'pfd' is the
pagefield which I want to make optional.
Thank you!
===============================================================
Public Function CreatePvt(snm, ptn, rfd, cfd, dfd, fun, cal, nft, cap,
pos, stl, pfd)
Set pt = _
PC.CreatePivotTable(TableDestination:=ActiveSheet.Cells(dr + 5, 1),
TableName:=ptn)
'-------------add row column and page fields
pt.AddFields RowFields:=rfd, ColumnFields:=Array(cfd), PageFields:=pfd
'-------------add data fields
With pt.PivotFields(dfd)
.Orientation = xlDataField
.Function = fun
.Caption = cap
.Calculation = cal
.Position = pos
.NumberFormat = nft
End With
Set pt = Nothing
End Function