I am writing an Excel Macro that should create a bar graph with custom error bars (Standard error of mean, calculated on the sheet). But I got stuck with including the values.
This is what I want to accomplish:
The averages should be displayed in the bar graph, the calculated group standard errors should be added as values for the error bars.
This is the VBA code:
Dim ValueCell as Range
Set ValueCell = Range("B98:C103")
ValueCell.Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.FullSeriesCollection(1).HasErrorBars = True
Set ValueCell = Worksheets(SHEET_NAME).Range(Cells(108, 3), Cells(112, 3))
ActiveChart.FullSeriesCollection(1).ErrorBar Direction:=xlY, _
Include:=xlPlusValues, Type:=xlCustom, Amount:=ValueCell, _
PlusValues:=ValueCell
It got stuck when I include the Amount and/or PlusValues parameter. I get an "Application-defined or object-defined error". After running the code it includes the graph, but with fixed Error bars. I searched for similar answers, but none seem to work in my code. I tried different formats for those 2 parameters (range, arrays) but nothing seems to work. I also tried to record a macro and then extract the code I need, but it does not help. It should be possible, but I can't figure out how to.


PlusValuesparameter.