+ Reply to Thread
Results 1 to 2 of 2

Update Chart data in dynamic range

Hybrid View

  1. #1
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Update Chart data in dynamic range

    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 codes but I can't get it to work.

    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
    
    'Also tried other similar macros find on different sites:
    '------------------------------------------------
    Sub Test1()
    
    Dim ChData As Range
    Dim LR     As Long
    LR = Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Set ChData = Sheets("Chart").Range(Cells(4, 1), Cells(LR, 7))
    
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.PlotArea.Select
        Application.CutCopyMode = False
    
        With Sheets("Chart")
            ActiveChart.SetSourceData Source:=.Range(Cells(4, 1), Cells(LR, 7))  'runtime error 445, object doesn't support this action
        End With
    End Sub
    '------------------------------------------------
    Sub Test2()
    
    Dim ws As Worksheet
    Dim chto As ChartObject
    Dim cht As Chart
    Dim LR     As Long
    LR = Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
        Set ws = ThisWorkbook.Worksheets("Chart")
        Set chto = ws.ChartObjects("Chart 1")
        Set cht = chto.Chart
        'cht.SetSourceData Source:=ws.Range("A4:G24")                   'runtime error 445, object doesn't support this action
        cht.SetSourceData Source:=ws.Range(Cells(4, 1), Cells(LR, 7))   'runtime error 445, object doesn't support this action
    End Sub
    '------------------------------------------------
    Sub Test3()
    
    Dim ChData As Range
    Dim LR          As Long
    LR = Columns("A:G").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Set ChData = Sheets("Chart").Range(Cells(4, 1), Cells(LR, 7))
    ChData.Select
        
        'With ActiveSheet
            'On Error Resume Next                                                       'With "On Error": "Chart 1" is updated with new "Source" range!
                ActiveSheet.ChartObjects("Chart 1").Chart.SetSourceData Source:=ChData  'Without "On Error": runtime error 445, object doesn't support this action
                '.ChartObjects("Chart 1").Chart.SetSourceData Source:=ChData            '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.

  2. #2
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Update Chart data in dynamic range

    Please, can anyone help me with this problem?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to update chart using dynamic named range
    By VBAClueless in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2016, 07:03 AM
  2. [SOLVED] chart based on dynamic range which resizes as per data in range-formula / vba
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2014, 04:02 PM
  3. [SOLVED] Chart date labels don't update (using dynamic named range)
    By s80NL in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 01-04-2013, 11:35 AM
  4. Update Pivot table using a dynamic range for source data
    By Carl Thompson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2011, 08:20 AM
  5. Dynamic range to update chart, multiple series
    By staples in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 07-31-2009, 12:26 PM
  6. Update Chart data Range with VBA
    By Roger in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-10-2005, 10:06 AM
  7. [SOLVED] Update Chart data Range with VBA
    By Roger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2005, 10:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1