locked
VB in Excel-setting chart source data RRS feed

  • Question

  • I am attempting to create a macro that automatically creates charts for columns of data in a different sheet.

    I would like to replace the "hard coded" range property with a variable range(cells,cells) in order to cycle through several different columns of data.

     

    With the following line of code, I receive the error "Run-time error '1004':  Method 'Cells' of object '_Global' failed":

    ActiveChart.SetSourceData Source:=Sheets("TRESULTSdmp_3").Range(Cells(i + 1, j + 1), Cells(i + m, j + 1)), PlotBy:=xlColumns

     

    A line of code that works is:

    ActiveChart.SetSourceData Source:=Sheets("TRESULTSdmp_3").Range("O2:0103"), PlotBy:=xlColumns

     

    However, this does not allow me to insert the line of code in a while loop which changes the selected range for each new chart.

     

    Is there some other range or cell designation that will work?

    Thursday, September 13, 2007 1:03 PM

Answers

  • jk2880, see the example which I have given you. It works there

    Do you use only VBA, or you make it in VB-6 or VB.NET?

    Monday, September 17, 2007 12:56 PM

All replies

  • Move the thread from Visual Basic General. There are more exports on supporting Visual Basic for Applications in this forum. I believe you are able to get the satisfying answers in this forum.

     

    Thanks again for your question.

    Monday, September 17, 2007 9:36 AM
  • jk2880, see the example which I have given you. It works there

    Do you use only VBA, or you make it in VB-6 or VB.NET?

    Monday, September 17, 2007 12:56 PM

  • bi-lya:

    Thank you very much for the example.  I was able to use it in my macro with only a small change...and it worked!  I only have VBA.

    Thanks again!
    Thursday, September 20, 2007 10:14 PM