Update Chart SourceData in dynamic range

soidog

New Member
Joined
May 26, 2016
Messages
45
Hi all,
I am using Excel 2016 and want to update a "Box and Whisker" chart with new "Source Data" in a dynamic range.
One workaround is to delete "Chart 1" and create a new "Box and Whisker" chart but how to update existing chart?
I have tried below code and others but I can't get it to work.

Code:
Sub ChartData1()
Dim ChartRange1 As Range
Dim LR          As Long
LR = Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

    With ActiveSheet.ChartObjects("Chart 1").Chart.ChartArea
        'On Error Resume Next                                                    'With "On Error": "Chart 1" is updated with new "Source" range!
            ActiveChart.SetSourceData Source:=Range(Cells(4, 1), Cells(LR, 7))   'Without "On Error": runtime error 445, object doesn't support this action
        'On Error GoTo 0
    End With
End Sub

Any help is much appreciated.
 
Replying to the first post in the thread.

This code should work better:

Code:
Sub UpdateChartData()
    Dim LR As Long
    LR = ActiveSheet.Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

    ActiveChart.SetSourceData Source:=ActiveSheet.Range(ActiveSheet.Cells(4, 1), ActiveSheet.Cells(LR, 7))
End Sub
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Of course. Try this please.

Code:
Sub ChartData1()
  Dim lr          As Long
  lr = Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
  ActiveSheet.ChartObjects("Chart 1").Activate
  ActiveChart.SetSourceData Source:=activesheet.Range("$A$4:$G$" & lr)
End Sub
 
Upvote 0
Jon Peltier, DanteAmor:


When I click in chart, range("A4:G15") is selected. Every cell in that range has a number.
Then I add a number in range("A16") and run your codes.


Jon Peltier:
I changed your code to:
Code:
Sub UpdateChartData()
    Dim LR As Long
    LR = ActiveSheet.Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).row
    ActiveSheet.ChartObjects("Chart 1").Activate    'added by soidog
    ActiveChart.SetSourceData Source:=ActiveSheet.range(ActiveSheet.Cells(4, 1), ActiveSheet.Cells(LR, 7))
End Sub

Both your codes still gives me: "runtime error 445, Object doesn't support this action", at last line in code.
If I click "Debug" in error popup window, chart is updated to the new SourceData range: range("A4:G16")!
If I click "End", chart is not updated.

Thanks
 
Upvote 0
I don't know why you're seeing that error. The code runs fine here, and it looks like it should run fine. There may be something funky in your installation.
 
Upvote 0
Jon Peltier, DanteAmor:

Until now I have only tested your codes in a "Box & Whisker" chart.
But today when I changed to some other chart types, like "Column", "Line", and "Pie", and run your codes it works!
I also tried the "Waterfall" chart but that didn't work. I have not tested all of the chart types.
So my question to you is: Have you run your code in a "Box & Whisker" chart without errors?


Thanks
 
Upvote 0
I did not try a waterfall chart or any of the conventional charts. But I did try a box and whisker chart, since you specifically mentioned it. And the code worked fine, without the error you report.
 
Upvote 0
That is so strange. I guess it must be something in my Excel 2016 settings.
For the moment, I give up! I have already spent too much time on this topic and I thank both of you for trying to help me.
I will continue with creating a new chart each time I need an update of "SourceData".
I will keep the thread open and hopefully someone else can help me.


Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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