我在Excel VBA中遇到了一些问题。当我尝试运行以下代码时;它说:
Error 1004:Unable to get the name property of the series class!
此错误发生在以下代码行中:(产品早先定义为字符串Zyvox及其他代码)
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
答案 0 :(得分:2)
Amit,我在示例工作表上运行了您的代码,它运行正常!唯一缺少的是变量product
的声明和设置,但是你提到你做到了。因此,首先要确保将product
声明为字符串并具有内容。然后,在行中设置断点
If namec.Name = product Then并运行代码。检查
namec.Name
和product
的内容,看看它的不同之处