0

I have a need to refer to a seriescollection by name. The MSDN object model page for seriescollection states either an index or a name can be used. However when I try to use a string variable I get error 1004 'Invalid parameter':

Dim sSeriesName As String
dim aRootCats() as string
Dim cSeriesCol As SeriesCollection

For x = 0 To UBound(aRootCats)
    sSeriesName = aRootCats(x)
    Set cSeriesCol = cChart.ChartGroups(1).SeriesCollection(sSeriesName)
Next x

I've tried the following too:

    sSeriesName = CStr(aRootCats(x)) ' just in case, because I filled this array with variant data type earlier
    Set cSeriesCol = cChart.ChartGroups(1).SeriesCollection(sSeriesName)

and

    Set cSeriesCol = cChart.ChartGroups(1).SeriesCollection(aRootCats(x))

and

    Set cSeriesCol = cChart.ChartGroups(1).SeriesCollection("Product Support")

UPDATE: I'm also experiencing the same error when looping on the seriescollection:

For c = 1 To cChart.ChartGroups(1).SeriesCollection.Count
    Set cSeriesCol = cChart.ChartGroups(1).SeriesCollection(c)
Next c

Any ideas?

Many thanks.

8
  • Generally you'd get that error if the series name doesn't match. Commented Mar 2, 2016 at 14:45
  • Thanks but it definitely does, in debugging I got the exact names with cChart.ChartGroups(1).SeriesCollection(1).name etc Commented Mar 2, 2016 at 14:46
  • So testing something like aRootCats(x) = cChart.ChartGroups(1).SeriesCollection(1).name returns True? Commented Mar 2, 2016 at 14:51
  • Yes, I get a true / false as appropriate. I'm thinking of doing this with another loop inside the first, this time on the series collection - is that your thought too? Commented Mar 2, 2016 at 14:53
  • Not really, since I can't replicate your error other than when the series name is incorrect. Can you put a file somewhere (OneDrive / Dropbox etc) showing the problem? If it's a bug, I'll report it. Which version of Excel are you using? Commented Mar 2, 2016 at 14:55

1 Answer 1

1

Because you are using a ChartGroup not a Chart, you have to use the Item property of the SeriesCollection and you have to pass a variant. Use either:

cChart.ChartGroups(1).SeriesCollection.Item(1)

or:

cChart.ChartGroups(1).SeriesCollection.Item(CVar(sSeriesName))

(or declare the variable as Variant rather than String)

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, declaring as variant works. Thanks for all your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.