Filippo
Filippo

Reputation: 320

VBA pie chart with dynamic data

I am trying to insert data in my pie chart but something goes wrong.

Apparently, VBA does not like this:

  ActiveChart.SeriesCollection(1).Name = ws2.Range(ws2.Cells(r, 2), ws2.Cells(r + inc, 2))

  ActiveChart.SeriesCollection(1).Values = ws2.Range(ws2.Cells(r, 15), ws2.Cells(r + inc, 15))

So I have tried this:

ActiveChart.SeriesCollection(1).Name = "=Dashboard!$B$"&r&":$B$"&r+inc

But it is still not working....

Upvotes: 0

Views: 776

Answers (1)

Mike
Mike

Reputation: 16

Try using a range declared inside your code and the SetSourceData method:

Set my_range = work.Range("E1:F" & i - 1)
dash.ChartObjects("My Chart").Chart.SetSourceData Source:=my_range

That is what works for me.

Upvotes: 0

Related Questions