What is the proper code if the title of your columns change? I am working on a manufacturing capacity outlook file that changes weekly. I need to have my column names in my pivot table change to the upcoming weeks.
So instead of: ActiveSheet.PivotTables(“PivotTable5”).AddDataField ActiveSheet.PivotTables( _
“PivotTable5”).PivotFields(“19-Oct-21”), “Sum of 19-Oct-21”, xlSum
I need: ActiveSheet.PivotTables(“PivotTable5”).AddDataField ActiveSheet.PivotTables( _
“PivotTable5”).PivotFields(E2), “Sum of “E2, xlSum
But I get an error message Expected: end of statement with E2 highlighted after “Sum of”.
So instead of: ActiveSheet.PivotTables(“PivotTable5”).AddDataField ActiveSheet.PivotTables( _
“PivotTable5”).PivotFields(“19-Oct-21”), “Sum of 19-Oct-21”, xlSum
I need: ActiveSheet.PivotTables(“PivotTable5”).AddDataField ActiveSheet.PivotTables( _
“PivotTable5”).PivotFields(E2), “Sum of “E2, xlSum
But I get an error message Expected: end of statement with E2 highlighted after “Sum of”.