如何使用vba查找系列名称?

时间:2012-11-13 15:12:39

标签: vba excel-vba excel

我已经编写了用于在图表中命名系列的vba代码:

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

我的问题是我想使用vba代码找到特定的系列名称。 在上面的代码中我有两个系列。 现在我想通过使用vba代码找到系列名称(manju)。

1 个答案:

答案 0 :(得分:9)

要通过传递名称来访问SeriesCollection()

MsgBox ActiveChart.SeriesCollection("manju").Name

这是可能的,因为index中的SeriesCollection(index)实际上是Variant类型,因此如果您传递String类型并尝试按名称访问它,则编译器会运行或者如果您要传递Long/Integer或任何其他数字数据类型)来访问枚举器。

或迭代SeriesCollection,将当前名称与“manju”进行比较:

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