Results 1 to 3 of 3

Thread: Change Chart Data Source To Different Column Ranges Using VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Change Chart Data Source To Different Column Ranges Using VBA

    Hi

    I spent last day or so trying to create a macro that would update the data source of the series in the chart. I went thorugh dozens of solutions which I found on the net and none of them are doing what I need them to do.

    The problem is that the series of data on the chart pull data from different columns of the data source table.

    This is what I get when I update the Data Source and record the macro:

    Code:
    ActiveChart.SetSourceData Source:=Sheets(1).Range("L12:L65,N12:N65")
    what I would like to replace it with is the following:

    Code:
    Dim MyDataSource1 as Range
    Dim MyDataSource2 as Range
    
    
    LastCellColumnL = ....
    LastCellColumnN = ...
    Set MyDataSource1 = ActiveSheets.Range(L12, LastCellColumnL)
    Set MyDataSource2 = ActiveSheets.Range(N12, LastCellColumnN)
    
    ActiveChart.SetSourceData Source:=Sheets(1).Range(MyDataSource1,MyDataSource2)
    The problem is that why I do this, it does not treat it the same way as the original line, it also includes all the columns in between the two data ranges.
    How to make

    Code:
    ActiveChart.SetSourceData Source:=Sheets(1).Range(MyDataSource1,MyDataSource2)
    to work like:

    Code:
    ActiveChart.SetSourceData Source:=Sheets(1).Range("L12:L65,N12:N65")
    and only include the two columns like in the original line here?

    Rafal
    Last edited by Admin; 04-26-2013 at 04:42 PM. Reason: code tag added

Similar Threads

  1. Replies: 1
    Last Post: 05-03-2013, 04:41 PM
  2. Replies: 3
    Last Post: 03-05-2013, 03:57 PM
  3. VBA code to copy data from source workbook
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 07-30-2012, 09:28 AM
  4. Replies: 3
    Last Post: 05-14-2012, 11:30 AM
  5. Get Chart's Source Data VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 11-24-2011, 07:54 AM

Posting Permissions

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