Hi!
I've recently entered the wonderful world of VBA and this forum really helped me forward! So hoping that this question also finds its way
Current situation: I've created a PivotTable in VBA with 3 row fields and 4 calculated data fields (2 x Average and 2 x the corresponding standard deviation)
Problem: when creating a PivotChart from the PivotTable (column clustered), all calculated fields are shown. I'm currently stuck on trying to create a column clustered graph, showing the calculated averages as columns and the corresponding standard deviation as Error Bars (so the Stdev of Strength is plotted onto the column Av strength, and the stdev of breakage onto column of Av Breakage).
Could someone help me out?
Thank you for any feedback!!
Below, you'll find my current code and PivotTable
PivotTable:
Code for PivotChart:
Sub CreatePivotChartEmbedded()
Dim sh As Shape
Dim ws As Worksheet
Dim ch As Chart
Dim pt As PivotTable
DeleteAllChartsObjects
Set ws = Worksheets("PivotTable")
Set sh = ws.Shapes.AddChart2( _
XlChartType:=XlChartType.xlColumnClustered, _
Width:=500, Height:=400)
Set ch = sh.Chart
sh.Name = "ColumnChart1"
Set pt = ws.PivotTables("OverviewPivotTable")
ch.SetSourceData pt.TableRange1
sh.Top = pt.TableRange1.Top
sh.Left = pt.TableRange1.Left + pt.TableRange1.Width + 50
End Sub
Sub DeleteAllChartsObjects()
Dim co As ChartObject
For Each co In Worksheets("PivotTable").ChartObjects
co.Delete
Next co
End Sub
Current PivotChart:
I've recently entered the wonderful world of VBA and this forum really helped me forward! So hoping that this question also finds its way
Current situation: I've created a PivotTable in VBA with 3 row fields and 4 calculated data fields (2 x Average and 2 x the corresponding standard deviation)
Problem: when creating a PivotChart from the PivotTable (column clustered), all calculated fields are shown. I'm currently stuck on trying to create a column clustered graph, showing the calculated averages as columns and the corresponding standard deviation as Error Bars (so the Stdev of Strength is plotted onto the column Av strength, and the stdev of breakage onto column of Av Breakage).
Could someone help me out?
Thank you for any feedback!!
Below, you'll find my current code and PivotTable
PivotTable:
Code for PivotChart:
Sub CreatePivotChartEmbedded()
Dim sh As Shape
Dim ws As Worksheet
Dim ch As Chart
Dim pt As PivotTable
DeleteAllChartsObjects
Set ws = Worksheets("PivotTable")
Set sh = ws.Shapes.AddChart2( _
XlChartType:=XlChartType.xlColumnClustered, _
Width:=500, Height:=400)
Set ch = sh.Chart
sh.Name = "ColumnChart1"
Set pt = ws.PivotTables("OverviewPivotTable")
ch.SetSourceData pt.TableRange1
sh.Top = pt.TableRange1.Top
sh.Left = pt.TableRange1.Left + pt.TableRange1.Width + 50
End Sub
Sub DeleteAllChartsObjects()
Dim co As ChartObject
For Each co In Worksheets("PivotTable").ChartObjects
co.Delete
Next co
End Sub
Current PivotChart: