Name

chart.Axes([Type], [AxisGroup])

Synopsis

Returns one or all of the axes on a chart.

Argument

Settings

Type

For 2-D charts, xlCategory returns the x-axis; xlValue returns the y-axis. For 3-D charts, xlSeries returns the z-axis.

AxisGroup

For 2-D charts, xlPrimary returns primary axis; xlSecondary returns the secondary axis. Default is xlPrimary. Cannot be xlSecondary for 3-D charts.

The following code applies labels to identify the x-, y-, and z-axes of a 3-D chart:

Sub LabelAxes(  )
    Dim chrt As Chart, ax As Axis
    Set chrt = Charts("Demo Chart Types")
    ' Activate the chart sheet.
    chrt.Activate
    ' Change chart type to 3-D.
    chrt.ApplyCustomType xl3DLine
    ' Get the category axis.
    Set ax = chrt.Axes(xlCategory)
    ' Add a title.
    ax.HasTitle = True
    ' Set the title.
    ax.AxisTitle.Caption = "Category"
    ' Repeat for value axis.
    Set ax = chrt.Axes(xlValue)
    ax.HasTitle = True
    ax.AxisTitle.Caption = "Value"
    ' Repeat for series axis.
    Set ax = chrt.Axes(xlSeries, xlPrimary)
    ax.HasTitle = True
    ax.AxisTitle.Caption = "Series"
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.