ErrorBars Members

Use the ErrorBars object to control the appearance of error bars on a chart. Use the Series object’s ErrorBar method to create error bars, and use the Series object’s ErrorBars property to get a reference to this object. The ErrorBars object has the following members. Key members (shown in bold) are covered in the following reference section:

Application
Border
ClearFormats
Creator
Delete
EndStyle
Name
Parent
Select

The ErrorBars object is similar to the DropLines, HiLoLines, DownBars, and UpBars objects. As with those objects, you can select, delete, or change the appearance of error bars. However, error bars have two additional members: EndStyle and ClearFormats. The following code adds error bars to a chart and changes their appearance:

Sub ErrorBarsMembers( )
    Dim chrt As Chart, sr As Series, eb As ErrorBars
    ' Get the chart.
    Set chrt = ActiveChart
    ' Make it a line chart
    chrt.ChartType = xlLine
    ' Get a series.
    Set sr = chrt.SeriesCollection(1)
    ' Add error bars.
    sr.ErrorBar xlY, xlErrorBarIncludeBoth, xlErrorBarTypeStError
    ' Format the error bars.
    sr.ErrorBars.EndStyle = xlCap
    sr.ErrorBars.Border.ColorIndex = 3
    ' Remove color
    'sr.ErrorBars.ClearFormats
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.