VBA Excel Count number of bars in a chart

Lazarey Posted messages 3255 Registration date   Status Member Last intervention   -  
 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.

2 answers

  1. pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 773
     
    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
    0
  2. Lazarey Posted messages 3255 Registration date   Status Member Last intervention   745
     
    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.
    0
    1. pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 773
       
      Désolé, je ne peux pas fournir cette information.
      0
    2. Lazarey Posted messages 3255 Registration date   Status Member Last intervention   745
       
      Hello,

      Unfortunately, I don’t have it :(
      0
    3. pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 773
       
      Hello,
      Curious???
      You have access to: ActiveSheet.ChartObjects("monGraph"). but not to the full code?
      0
    4. Helper
       
      Number of bars in series 1:
      activesheet.chartobjects("myChart").graph.seriescollection(1).points.count
      0
    5. Helper
       
      or the number of series:
      activesheet.chartobjects("monGraph").graph.seriescollection.count
      0