Reputation: 43
I am having some problem in Excel VBA. When I try to run the below code; it says:
Error 1004:Unable to get the name property of the series class!
This error happens at this line of code : (product is defined earlier as string Zyvox and others)
If namec.Name = product Then
What should I do? I have tried other things too like
ActiveChart.SeriesCollection(p).name = product
But to no avail! Please help!
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
Upvotes: 1
Views: 3410
Reputation: 17495
Amit, I ran your code on a sample worksheet and it works fine! The only thing that was missing is the declaration and setting of the variable product
, but you mentioned that you did that. So, first make sure that product
is declared as string and has the content. Then, set a breakpoint in the line
If namec.Name = product Thenand run the code. Inspect the content of both,
namec.Name
as well as product
and see where it differs
Upvotes: 2