Class CategoryCollection (Excel VBA)

The class CategoryCollection represents the collection of visible chart categories in the chart. To use a CategoryCollection class variable it first needs to be instantiated, for example


Dim ccn as CategoryCollection
Set ccn = ActiveChart.ChartGroups(1).CategoryCollection()

For Each

Here is an example of processing the CategoryCollection items in a collection.


Dim chrcCategoryCollection As ChartCategory
For Each chrcCategoryCollection In ActiveChart.ChartGroups(1).CategoryCollection()
	
Next chrcCategoryCollection

Count

Returns a Long value that represents the number of objects in the CategoryCollection (returns the number of categories visible in the chart).


Dim lngCount As Long
lngCount = ActiveChart.ChartGroups(1).CategoryCollection.Count

Item

Returns a single object from the CategoryCollection object.

Item (Index)

Index: The index number for the object.


Dim chrcCategoryCollection As ChartCategory
Set chrcCategoryCollection = ActiveChart.ChartGroups(1).CategoryCollection(Index:=1)