VBA code to Update all the graph in a workbook

Russel225

Board Regular
Joined
Dec 28, 2012
Messages
53
Hi,

I have many graph in several sheets, each time when data changes, I have to update all the charts data, one by one. so I need a code which can update all the charts in that worksheet.

charts and data are on different sheets.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Derek,

Sorry for late reply, yes, there is No need for <acronym title="visual basic for applications">VBA</acronym> code to do this. but I have to do this for, more than eighty graph's.
In future I will take care of this problem but for now, I need a code to do this.
 
Upvote 0
If you VBA change the data doesn't that update the chart(s)? Here's some code that removes the original chart and builds the same type with the new specified data... seems abit much when the dynamic thing is available. Maybe the code will help. ****Use this code only on a copy of your wb in case something goes wrong. Dave
Code:
Sub UpdateChart()
Dim Ctype As String, X1Value As Range, Y1Value As Range
Dim ChartRange As Range
Application.ScreenUpdating = False
With Worksheets("Sheet1") 'change to suit
    'loop charts
    For cnt = .ChartObjects.Count To 1 Step -1
    'delete chart
    .ChartObjects(cnt).Chart.ChartArea.Select
    Ctype = .ChartObjects(cnt).Chart.ChartType
    ActiveWindow.Visible = False
    .ChartObjects(cnt).Chart.Parent.Delete
    'add new chart
    'set new chart x values
    Set X1Value = Sheets("Sheet1").Cells(1, 1)
    'set new y values
    Set Y1Value = Sheets("Sheet1").Cells(5, 2)
    Set ChartRange = Sheets("Sheet1").Range(X1Value, Y1Value)
    Charts.Add.Location Where:=xlLocationAsObject, Name:="Sheet1"
    ActiveChart.ChartType = Ctype
    ActiveChart.SetSourceData Source:=ChartRange, PlotBy:=xlColumns
    Next cnt
End With
Application.ScreenUpdating = True
End Sub
ps. data in A1:B5 in this eg
 
Upvote 0
Hi NdNoviceHlp,

Thanks for your effort but, this is not what I need.
you see, I have more than 10 sheet's in each workbook, each having multiple charts, so basically it's like building from scratch.
there must be a way to update those chart by VBA code.
 
Upvote 0
Charts update automatically... What exactly do you mean by updating here?
ξ
 
Upvote 0
Hi xenou

I have fixed excel template, In which every time I have to enter new data. I simply mean, when I update the data, the chart should be updated automatically.

I know excel table's has that feature also index and match can be used, but I have no control over Fixed Excel template.

Now after updating data, I have to manually go to every chart and update the data ( More than 60 chart's)

I hope it's clear why I need a code.
 
Last edited:
Upvote 0
Have the same problem...

VBA defined series (assigning .XValues & .Values from arrays) in XYScatter plot. Macros work perfectly. But, chart display of series does not occur.

Have to right-click on plot area and select "select data." Select Data Source dialog window pops-up. I cancel out of that and the series appear in plot area when the window disappears.

Find the code here: Excel 2013 VBA Defined Series Not Plotting - Stack Overflow

Anyone know any way to refresh the plot area of the chart? Chart.Refresh does not work.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,208
Members
448,874
Latest member
Lancelots

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top