Home » excel » excel vba – how to find the series name using vba?

excel vba – how to find the series name using vba?

Posted by: admin March 9, 2020 Leave a comment

Questions:

I have written vba code for naming the series in a graph:

 ActiveChart.SeriesCollection(1).name = "SPEC"
 ActiveChart.SeriesCollection(2).name = "manju"

My problem is that I want to find the particular series name using vba code.
In the above code I have two series.
Now I want find the series name (manju) by using vba code.

How to&Answers:

To access the SeriesCollection() by passing the name you can:

MsgBox ActiveChart.SeriesCollection("manju").Name

That’s possible because index in the SeriesCollection(index) is actually of Variant type so the compiler works out if you are passing a String type and trying to access it by name or if you are passing a Long/Integer (or any other numeric data type) to access the enumerator.

or iterate the SeriesCollection, comparing the current name against “manju”:

For i = 1 to ActiveChart.SeriesCollection.Count
   If ActiveChart.SeriesCollection(i).name = "manju" Then
      MsgBox "Found it!"
      Exit for
   End if
Next