在VBA Excel中的图表中命名系列集合时出错
我在Excel VBA中遇到了一些问题。 当我尝试运行下面的代码时; 它说:
Error 1004:Unable to get the name property of the series class!
这个错误发生在这行代码:(产品被定义为stringZyvox和其他)
If namec.Name = product Then
我该怎么办? 我也尝试过其他的东西
ActiveChart.SeriesCollection(p).name = product
但无济于事! 请帮忙!
Public Sub chartBlue() Dim i As Integer, j As Integer, p As Integer, namec As Series For i = 4 To Sheets.Count Sheets(i).Activate For j = 1 To Sheets(i).ChartObjects.Count Sheets(i).ChartObjects(j).Activate ActiveChart.ChartArea.Select For p = 1 To ActiveChart.SeriesCollection.Count Set namec = ActiveChart.SeriesCollection(p) If namec.Name = product Then namec.Border.ColorIndex = 5 End If Next p Next j ' Windows(Reportname).Activate Sheets(i).Range("A1").Activate Next i End Sub
阿米特,我在示例工作表上运行你的代码,它工作正常! 唯一缺less的是variablesproduct
的声明和设置,但是你提到你是这么做的。 所以,首先确保product
声明为string,并具有内容。 然后,在行中设置一个断点
如果namec.Name = product那么
并运行代码。 检查namec.Name
以及product
,看看它们的不同之处