Hi
I am currently building an Excel VBA reporting project .
One requirement is for there to be a Pivot Table, which can be built dynamically/change it's fields depending on the source data.
It's all going well so far, but I have a problem as follows:
My Pivot table variables are as follows:
This code works fine:
ActiveSheet.PivotTables("ReportAnalytics_1").adddatafield ActiveSheet.PivotTables("ReportAnalytics_1").PivotFields(PivotDataFieldName), "Count of Stocking ID", xlCount
This code does not work:
ActiveSheet.PivotTables("ReportAnalytics_1").adddatafield ActiveSheet.PivotTables("ReportAnalytics_1").PivotFields(PivotDataFieldName), PivotDataFieldCaption, xlCount
This code does not work:
ActiveSheet.PivotTables("ReportAnalytics_1").adddatafield ActiveSheet.PivotTables("ReportAnalytics_1").PivotFields(PivotDataFieldName), "Count of Stocking ID",PivotDataFieldAggregation
Any idea why it is happy enough using a variable for the Field name, but not for either the Caption or the Aggregation type?
Thanks a lot!
Fergal
I am currently building an Excel VBA reporting project .
One requirement is for there to be a Pivot Table, which can be built dynamically/change it's fields depending on the source data.
It's all going well so far, but I have a problem as follows:
My Pivot table variables are as follows:
- PivotDataFieldName
- PivotDataFieldCaption (value is the same as the Filed name - ie; unchanged)
- PivotDataFieldAggregation (eg; value is xlCount)
This code works fine:
ActiveSheet.PivotTables("ReportAnalytics_1").adddatafield ActiveSheet.PivotTables("ReportAnalytics_1").PivotFields(PivotDataFieldName), "Count of Stocking ID", xlCount
This code does not work:
ActiveSheet.PivotTables("ReportAnalytics_1").adddatafield ActiveSheet.PivotTables("ReportAnalytics_1").PivotFields(PivotDataFieldName), PivotDataFieldCaption, xlCount
This code does not work:
ActiveSheet.PivotTables("ReportAnalytics_1").adddatafield ActiveSheet.PivotTables("ReportAnalytics_1").PivotFields(PivotDataFieldName), "Count of Stocking ID",PivotDataFieldAggregation
Any idea why it is happy enough using a variable for the Field name, but not for either the Caption or the Aggregation type?
Thanks a lot!
Fergal