Calculated fields in PivotTable as Error Bars in Pivot chart (&no longer as column)

Flore L

New Member
Joined
Jul 29, 2021
Messages
1
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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:
1627545913775.png


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:
1627545988899.png
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,575
Messages
6,125,629
Members
449,241
Latest member
NoniJ

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top