Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

For loop with .CategoryCollection.item(i) returns "Invalid Parameter" error

$
0
0

I have a user form which has a button that I intend to edit a chart with. The chart has multiple categories, which I wish to select/deselect based on the currency indicated in the header of the column:

enter image description here

The problem I am facing is marked in the code below with a comment. Anybody has a clue why i, as a variant is not accepted by .item(i) as a valid parameter?

According to this documentation it should totally work :D

Private Sub CommandButton2_Click()

    Dim ActiveSheetChart As Chart
    Set ActiveSheetChart = Worksheets(ActiveSheet.Name).ChartObjects(1).Chart
    Dim i As Variant

        With ActiveSheetChart.ChartGroups(1)

            Debug.Print .FullCategoryCollection.Count

            For i = 1 To .FullCategoryCollection.Count

                Debug.Print .FullCategoryCollection(i).Name
                Debug.Print Right(ActiveSheetChart.ChartGroups(1).CategoryCollection.Item(i).Name, 4) = "PLN)"

                If Right(ActiveSheetChart.ChartGroups(1).CategoryCollection.Item(i).Name, 4) = "PLN)" Then

                    .FullCategoryCollection(i).IsFiltered = False

                Else:

                    .FullCategoryCollection(i).IsFiltered = True

                End If

            Next i

        End With 'categorycollection

End Sub

Viewing all articles
Browse latest Browse all 88835


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>