Locating a Specific Chart Axis

Every chart contains a WCAxes collection, which can contain up to eight category and value axes. This collection is unordered, so locating a specific axis requires enumerating the collection.

Example 1: Find and return the first category axis.

Function FindCategoryAxis(chart)
   Dim i, c
   
   Set c = chart.Parent.Constants
   For i = 0 To chart.Axes.Count - 1
     If chart.Axes(i).Type = c.chCategoryAxis Then
        Set FindCategoryAxis = chart.Axes(i)
        Exit Function
     End If
   Next
   Set FindCategoryAxis = Nothing
End Function

Example 2: Find and return the first vertical value axis.

Function FindVerticalValueAxis(chart)
   Dim i, c
   
   Set c = chart.Parent.Constants
   For i = 0 To chart.Axes.Count - 1
     If chart.Axes(i).Type = c.chValueAxis And _
       (chart.Axes(i).Position = c.chAxisPositionLeft Or _
        chart.Axes(i).Position = c.chAxesPositionRight) Then
           Set FindVerticalValueAxis = chart.Axes(i)
           Exit Function
     End If
   Next
   Set FindVerticalValueAxis = Nothing
End Function