VBA Excel Count number of bars in a chart
Lazarey
Posted messages
3255
Registration date
Status
Member
Last intervention
-
Helper -
Helper -
Hello everyone,
I have a small question regarding VBA in Excel. I would like to know if it is possible to count the number of bars in a chart. In fact, I have a chart that is generated automatically and I don't know how to find out the number of bars it contains.
Thank you very much.
I have a small question regarding VBA in Excel. I would like to know if it is possible to count the number of bars in a chart. In fact, I have a chart that is generated automatically and I don't know how to find out the number of bars it contains.
Thank you very much.
2 answers
-
Hello,
If I'm not mistaken, your number of bars corresponds to the number of data points you put in your graph.
For me, it's enough to count these data points to get the number of "bars".
Example:
We create a graph from the cells A1:B10
The code:
MsgBox Sheets("Sheet1").Range("A1:B10").Cells.Count / 2
will give us the number of "bars" if all the cells are filled, of course.
--
Franck P -
Hi Pijaku.
Thank you for your response, but I had already tried and since the chart is generated from a subset of the data table, this method doesn't work. Hence my need to count the number of bars in the chart.
I looked into the methods and properties of the chart to see what I could put after the ""." of the following code:ActiveSheet.ChartObjects("monGraph").
But I didn't find anything really helpful. Maybe with the "seriescollection" object, but I also didn't find anything.