Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '1004' Unable to get xxx property of the xxx class

Status
Not open for further replies.

Sean7174

Programmer
Joined
Jul 17, 2003
Messages
13
Location
US
How do you handle Run-time error '1004'? I ave gotten it under several different cases. There is the one I am having issues with now.

I am trying to write a loop that goes trough all Series of all graphs in a workbook, and only act on ones names "Spec". I am using te following method:

For Each WorkChart in ActiveWorkbook.Charts
For Each WorkSeries in WorkChart.SeriesCollection
If WorkSeries.Name = "Spec" Then
...
endif
Next WorkSeries
Next WorkChart

The issue is, if a series gets deleted, it leaves a "undefined" series in its place. When it tries to get the .Name of this undefined series, it causes the Runtime Error 1004. Is there any way to test if a property such as .Name is defined before trying to use it?

Thanks.
 
You could just put a label on your loop and an error trapper in that says:

on error goto errorhandler:

For Each WorkChart in ActiveWorkbook.Charts
For Each WorkSeries in WorkChart.SeriesCollection
If WorkSeries.Name = "Spec" Then
...
endif
XX: Next WorkSeries
Next WorkChart


ErrorHandler:

If err.number = 1004 then
err.clear
goto XX:
end if

I know it's a bit rough but at least it's a workaround.

Hope it helps

Asjeff
 
Untested but usually with deletions, it is best to work backwards - you could try:

For i = workchart.seriescollection.count to 1 step -1
If WorkSeries.Name = "Spec" Then
.....

next i


Rgds, Geoff
Si hoc legere scis, nimis eruditionis habes
Want the best answers to your questions ? - then read me baby one more time - faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top