Name

series.ErrorBar(Direction, Include, Type, [Amount], [MinusValues])

Synopsis

For 2-D chart types, adds error bars to the series. Causes an error for 3-D chart types.

Argument

Settings

Direction

An xlErrorBarDirection constant that specifies the axis direction for the bar. Possible settings are xlX or xlY.

Include

An xlErrorBarInclude constant that specifies the type of bar. Possible settings are xlErrorBarIncludeBoth, xlErrorBarIncludeNone, xlErrorBarIncludeMinusValues, or xlErrorBarIncludePlusValues.

Type

An xlErrorBarType constant that specifies the calculation used to size the bar. Possible settings are xlErrorBarTypeCustom, xlErrorBarTypePercent, xlErrorBarTypeStError, xlErrorBarTypeFixedValue, or xlErrorBarTypeStDev.

Amount

If Type is xlErrorBarTypeCustom, the positive value of the bar.

MinusValues

If Type is xlErrorBarTypeCustom, the negative value of the bar.

The following code adds error bars to the first series of the active chart:

Sub AddErrorBars(  )
    Dim chrt As Chart, sr As Series
    ' Get a chart.
    Set chrt = ActiveChart
    ' Use 2-D chart type.
    chrt.ChartType = xlLineMarkers
    ' Get first series
    Set sr = chrt.SeriesCollection(1)
    ' Add error bars.
    sr.ErrorBar xlY, xlErrorBarIncludeBoth, xlErrorBarTypeStError
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.