Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetSourceData Source question...

Status
Not open for further replies.

danomaniac

Programmer
Jan 16, 2002
266
US
Hi gang.

I'm creating an app in VB6 that opens Excel, populates it with some data, then creates a chart from the data. I'm having trouble setting the SourceData Source for my chart object. The number of data entries varies so I can't set my source as an absolute reference.

I've used this and it works...

ActiveChart.SetSourceData Source:=Sheets("Results").Range("A14:D25"), PlotBy _
:=xlColumns

But I need to set the range using a variable. I've managed to figure out how to create a variable sized named range depending on how many lines will be populated, but I can't figure out how to make this work...

ActiveChart.SetSourceData Source:=Sheets("Results").Range("Range1"), PlotBy _
:=xlColumns

Any help would be appreciated. Thanks.
 
To use a dynamic range, I THINK (please correct me if I'm wrong) that you have to manually add a dynamic name for each data series in the chart. To do it dynamically in code, try:
ActiveChart.SetSourceData Source:=Sheets("Results").Range("A14:D" & range("D65536").end(xlup).row), PlotBy _
:=xlColumns

you may need to use something like Current Region if you have more data below the chart data
HTH Rgds
~Geoff~
 
Thanks for the reply Geoff, I ended up getting it to work. My problem was the previous line was something like Sheets("Results").Select - I took that line out and it worked with the ...Sheets("Results").Range("Range1"), PlotBy ... line. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top