Problem with SeriesCollection

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Dear Mr Excel,

I have a SeriesCollection in my chart. I can access its points by:
Dim TSer
For Each TSer In Sheets("Chart1").SeriesCollection
Debug.Print TSer.Points.Count
Next

and Sheets("Chart1").SeriesCollection.count is 1.

But if I delete a data (not graph) from Sheets("Chart1"), the Sheets("Chart1").SeriesCollection.count is still 1!!!
and I have a run-time error 1004 in my code and I cann't access Series properties such as Point, Name and........
Any idea to solve the error?
How can I understand the Series has data or not?


Best Regads,
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You can not select it by right clicking!!!!! there is no graph in the chartsheet!!! but Sheets("Chart1").SeriesCollection.count is 1.

try this, draw a chart and then delete the data from sheets. The chartsheet is empty but Sheets("Chart1").SeriesCollection.count is 1


any help?
 
Upvote 0
How are you deleting the data?

If you just delete the cell contents the Series still has the same number of points as previously. If you delete the rows/columns containing the Series data, you get an invalid reference error when you activate the Chart Sheet. But there is still a Series with 1 point.
 
Upvote 0
I JUST delete the cell contents ... and the Series don't have the same number of points as previously because the following line showes an error!!!!
Sheets("Chart1").SeriesCollection(1).Points.Count
 
Upvote 0
Try this:

Code:
Sub Test()
    Dim Pts As Points
    On Error Resume Next
    Set Pts = Sheets("Chart1").SeriesCollection(1).Points
    If Err <> 0 Then
       MsgBox "No points"
    Else
       MsgBox Pts.Count & " points"
    End If
    On Error GoTo 0
End Sub
 
Upvote 0
When a series has no data, it is not plotted, and VBA cannot access the series. You can still manually get to it through the Source Data dialog, but VBA is a little stupid on this point. SeriesCollection.Count will include the series, but since it isn't plotted, SeriesCollection.Points.Count throws an error.

I haven't tried this yet myself, but a colleague of mine, Bill Manville, has suggested changing the chart to an area chart. Apparently VBA can access a data-less area chart series. When you have finished, change the chart back. The only difficulty is when you have a combo chart, and you have to revert each series to a different type. Iterate through the series and store the chart type; since our misbehaving series has no chart type (because it isn't plotted), you need to trap that error.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______
 
Upvote 0
Thanks my friends for the replys, I try the code...

Best Regards,
Hamid


P.S.: Dear jonpeltier, thanks for the good reply and your site....
 
Upvote 0

Forum statistics

Threads
1,221,711
Messages
6,161,450
Members
451,707
Latest member
PedroMoss2268

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top