Saturday, January 19, 2013

Macro to remove gridlines in chart

If you want to remove gridlines from the chart. Try this macro


















Sub remove_gridlines()

    Dim cht As Chart
    Dim axs As Axis
    
    ' change chart name here
    Set cht = Sheets("Sheet1").ChartObjects("Chart 3").Chart
    
    For Each axs In cht.Axes
        axs.HasMajorGridlines = False
        axs.HasMinorGridlines = False
    Next
    

End Sub

----------------------------------------------------------------------------------------------------------------------

Sub remove_specific_gridline()

Dim cht As Chart

'change chart name here
Set cht = Sheets("Sheet1").ChartObjects("Chart 3").Chart
    With cht.Axes(xlCategory, xlPrimary)
        'Hide Minor Gridline only
        .HasMajorGridlines = True
        .HasMinorGridlines = False
    End With

    With cht.Axes(xlValue, xlPrimary)
        'Hide both
        .HasMajorGridlines = False
        .HasMinorGridlines = False
    End With
  
End Sub

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...