DownBars and UpBars Members

Use the DownBars and UpBars objects to control the appearance of up and down bars on a chart. Use the ChartGroup object’s DownBars and UpBars properties to get a reference to these objects. The DownBars and UpBars objects have the following members:

Application

Border

Creator

Delete

Fill

Interior

Name

Parent

Select

 

The DownBars and UpBars objects are similar to the DropLines and HiLoLines objects. As with those objects, you can select, delete, or change the appearance of up and down bars. However, up and down bars have an interior region that you can control using two additional members: Fill and Interior. Be sure to check the ChartGroup object’s HasUpDownBars property before using these objects. The following code adds up and down bars to a chart and changes their appearance:

Sub DownBarsMembers( )
    Dim chrt As Chart, cg As ChartGroup
    ' Get the chart.
    Set chrt = ActiveChart
    ' Make it a line chart
    chrt.ChartType = xlLine
    ' Get the chart group.
    Set cg = chrt.LineGroups(1)
    ' Add down bars.
    cg.HasUpDownBars = True
    ' Format the up and down bars.
    On Error Resume Next
    cg.UpBars.Interior.ColorIndex = 1
    cg.DownBars.Interior.ColorIndex = 3
    On Error GoTo 0
End Sub

You should include the On Error Resume Next statement when working with up and down bars since the contents of the chart determine whether or not up bars, down bars, or both types of bars exist.

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.