Hide/Unhide Chart Axis

with tags excel DokuWiki -

Hide/Unhide Chart Axis

'// This takes a sheet name, where it is a chart sheet.
'// If your chart lives on a regular worksheet then you will probably need to add a call to Sheet.ChartObject("chart name")
Function ToggleChartAxisValues(sheetName As String)
    Dim c As Chart, isHidden As Boolean, ax As Axis
    Set c = Sheets(sheetName)
    Set ax = c.Axes(xlValue)
    isHidden = (ax.TickLabelPosition = xlTickLabelPositionNone)

    If isHidden Then
        '// Unhide
        ax.TickLabelPosition = xlTickLabelPositionNextToAxis
    Else
        '// Hide
        ax.TickLabelPosition = xlTickLabelPositionNone
    End If
End Function