Gridlines Members

Use the Gridlines objects to control the appearance of gridlines on a chart. Use the Axis object’s MajorGridlines and MinorGridlines properties to get a reference to this object. The Gridlines object has the following members:

Application
Border
Creator
Delete
Name
Parent
Select

Use the Axis object’s HasMajorGridlines or HasMinorGridlines to make sure these objects exist before using them. For example, the following code changes the appearance of the major gridlines for the value axis:

Sub FormatGridLines( )
    Dim chrt As Chart, ax As Axis, gl As Gridlines
    ' Get the chart.
    Set chrt = ActiveChart
    ' Get the value axis.
    Set ax = chrt.Axes(xlValue, xlPrimary)
    ' Make sure the gridlines exist.
    ax.HasMajorGridlines = True
    ' Get the gridlines
    Set gl = ax.MajorGridlines
    ' Make them blue.
    gl.Border.Color = &HFF0000
    ' Change the line style.
    gl.Border.LineStyle = XlLineStyle.xlDot
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.