Pages

Saturday, January 19, 2013

Macro to add gridlines in chart

If you want to add gridlines in chart . Try this macro






Sub add_Gridlines()
    Dim cht As Chart
    ' change chart name here
    Set cht = Sheets("Sheet1").ChartObjects("Chart 3").Chart
        
    With cht.Axes(xlCategory, xlPrimary)
    .HasMajorGridlines = True
    .MajorGridlines.Border.Color = RGB(186, 12, 255)
    .MajorGridlines.Border.LineStyle = xlContinuous
    .MajorGridlines.Border.Weight = xlThin
    .HasMinorGridlines = False
    End With
    
    With cht.Axes(xlValue, xlPrimary)
    .HasMajorGridlines = False
    .HasMinorGridlines = True
    .MinorGridlines.Border.Color = RGB(186, 12, 10)
    .MinorGridlines.Border.LineStyle = xlDashDot
    .MinorGridlines.Border.Weight = xlThin
    End With
End Sub

No comments:

Post a Comment