Changing Source of Line Graph in Excel 2007 with VBA RRS feed

  • Question

  • Hi,

    I am hoping that some of you people will be able to help me with an issue I have..........


    I am trying to change the source data of a Line chart in Excel 2007, I want the data to change when I click on the graph and be a range that is in relation to a cell that is selected prior to the graph being clicked.

    I have picked up the row reference of the cell which is simple enough and fed this through to the module that I want to change the graph data in but no matter how I try I don't seem to be able to get the graph to change and keep getting a Runtime Error 438 Object Doesn't support this property or method!!

    Please excuse my simple code I am not  a programmer

    Dim rownumber As Integer
    Dim chtobj As ChartObject
    Sub Chart2_Click()
    rownumber = ActiveCell.Row
    Set chtobj = ActiveSheet.ChartObjects(2)
    With chtobj
        .SetSourceData Source:=("J" & rownumber & ":AS" & rownumber)
        .ChartTitle = Range("H" & rownumber)
    End With
    End Sub

    Any help is greatly appreciated


    and while I am asking questions, is there anyway of changing the type of trendline on a graph using vba, also extracting the formula from the trendline and putting it into a cell


    Many thanks



    • Moved by Cindy Meister MVP Thursday, January 12, 2012 3:20 PM not VSTO (From:Visual Studio Tools for Office)
    • Moved by 许阳(无锡) Tuesday, January 31, 2012 9:36 AM end-user issue (From:Excel for Developers)
    Wednesday, January 11, 2012 7:29 PM

All replies