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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13363284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:28:46  来源:igfitidea点击:

how to find the series name using vba?

vbaexcel-vbaexcel

提问by M_S_SAJJAN

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

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

 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.

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

回答by Lynn Crumbling

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

SeriesCollection()通过传递名称访问 ,您可以:

MsgBox ActiveChart.SeriesCollection("manju").Name

That's possible because indexin the SeriesCollection(index)is actually of Varianttype so the compiler works out if you are passing a Stringtype 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.

这是可能的,因为indexSeriesCollection(index)实际上的Variant类型,这样编译器的工作原理,如果你传递一个String类型,并试图通过名称访问它,或者如果你传递一个Long/Integer或任何其他数字数据类型)来访问枚举。

or iterate the SeriesCollection, comparing the current name against "manju":

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

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