O
OMER
Hola,
I crated this code using the Macro Recorder. The issue that I have is that
there are some fixed names within the code that should be variable, depending
on the source table column names. Is there a way to substitute ranges and
field names for variables?
Here is the relevant code:
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Inv_Graph'!$A$1:$C$18")
ActiveWorkbook.ShowPivotChartActiveFields = True
ActiveChart.ChartType = xlColumnClustered
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Organization")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField
ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Total Project Cost"), "Sum of Total
Project Cost", _
xlSum
For example, source data doesn't always has the column header as "Total
Project Cost", or "Total Resource"
Thank you in advance.
OMER
I crated this code using the Macro Recorder. The issue that I have is that
there are some fixed names within the code that should be variable, depending
on the source table column names. Is there a way to substitute ranges and
field names for variables?
Here is the relevant code:
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Inv_Graph'!$A$1:$C$18")
ActiveWorkbook.ShowPivotChartActiveFields = True
ActiveChart.ChartType = xlColumnClustered
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Organization")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField
ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Total Project Cost"), "Sum of Total
Project Cost", _
xlSum
For example, source data doesn't always has the column header as "Total
Project Cost", or "Total Resource"
Thank you in advance.
OMER