Updating charts in Excel

syed

Member
Hi,

Attached is the snap of my excel which contains charts. Once the new set of datas are inserted i need to update the data range of the graph with updated row number. Currently i am achieving this by the combination of sending global send key event and Region mode. It is working fine. But want this piece of functionality to be done using VBA script.

I tried with this piece of code

GetWorkbook(handle,Nothing).ActiveSheet.ChartObjects(chartName).Chart.SeriesCollection(1).Values= GetWorkbook(handle,Nothing).ActiveSheet.Range(chartRange)

ChartRange i am sending as "='Incident Assignee Breakdown'!$B$5:$D$4986" .

But it is throwing error stating that SeriesCollection(1) is not memeber of Chart object. Can any one help me in resolving this?

@VJR you can throw some light on this.
 

Attachments

  • Chart.PNG
    119.2 KB · Views: 22

VJR

Well-Known Member
Convert this line to your code
ActiveSheet.ChartObjects(1).Chart.SetSourceData (Source:=Range("Sheet1!A1:B5"))
 

syed

Member
@VJR Thanks VJR


It worked after changing like this

GetWorkbook(handle,Nothing).ActiveSheet.ChartObjects(chartName).Chart.SetSourceData (Source:=GetWorkbook(handle,Nothing).ActiveSheet.Range(chartRange))

Now I am facing one more issue with different graph(PFA Pic).

If you see the pic1 there is no Chart data range. In this case i need to click each series then i need to update the series value as in pic2.

For this I am using below piece of code

GetWorkbook(handle,Nothing).ActiveSheet.ChartObjects(chartName).Chart.SeriesCollection(1).XValues = "='Incident Assignee Breakdown'!$C$4946"

Code is not throwing any error but at the same time it is not updating the graph.

Is there anything i am missing?
 

Attachments

  • Capture1.PNG
    87.2 KB · Views: 19
  • Capture2.PNG
    125.2 KB · Views: 17

VJR

Well-Known Member
Have you checked with a valid range of data

= "='Incident Assignee Breakdown'!$C$4946"

= "='Incident Assignee Breakdown'!$A$1:$C$4946"
 
Top