VBA Count number of series in a chartObject

2020-04-15 15:09发布

I know this seems straightforward but it doesn't seem to work for me. I have a chart on "Sheet1". It is the only chart on the sheet. I want to get the number of series in the chart. So I use:

Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).SeriesCollection.Count

to get the answer in the immediate window. However VBA gives me a "Object doesn't support property or method" error. Any ideas?

2条回答
对你真心纯属浪费
2楼-- · 2020-04-15 15:26

You need to add in Chart:

Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection.Count
查看更多
Explosion°爆炸
3楼-- · 2020-04-15 15:26

Try this Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection.Count

查看更多
登录 后发表回答