Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Setting Range in Graph

I have a worksheet called graphdata and another called charts. on the charts
worksheet there is chart 4. I am trying to dynamically set the range for the
chart as follows

Sheets("Charts").Activate
Range("A1").Select
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "=GraphData!$B$4:$B" & lastrow
ActiveChart.SeriesCollection(2).Values = "=GraphData!$C$4:$C" & lastrow
ActiveChart.SeriesCollection(3).Values = "=GraphData!$I$4:$i" & lastrow

lastrow is determined by using another and in this particular case is 34.

the actual chart series reads

=GraphData!$B$4:$B$32 and its that last number I want to dynamically change
depending on the number of rows in the data

Any suggestions
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Setting Range in Graph

Any suggestions,

The Series Values accepts a Range object or an array of values.
You have neither. Something like the following should work, assuming that
"lastrow" actually contains a numeric value...

With Worksheets("GraphData")
ActiveChart.SeriesCollection(1).Values = .Range(.Cells(4, 2), .Cells(lastrow, 2))
ActiveChart.SeriesCollection(2).Values = .Range(.Cells(4, 3), .Cells(lastrow, 3))
ActiveChart.SeriesCollection(3).Values = .Range(.Cells(4, 9), .Cells(lastrow, 9))
End With

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Nigel"
wrote in message
...
I have a worksheet called graphdata and another called charts. on the charts
worksheet there is chart 4. I am trying to dynamically set the range for the
chart as follows

Sheets("Charts").Activate
Range("A1").Select
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "=GraphData!$B$4:$B" & lastrow
ActiveChart.SeriesCollection(2).Values = "=GraphData!$C$4:$C" & lastrow
ActiveChart.SeriesCollection(3).Values = "=GraphData!$I$4:$i" & lastrow

lastrow is determined by using another and in this particular case is 34.

the actual chart series reads

=GraphData!$B$4:$B$32 and its that last number I want to dynamically change
depending on the number of rows in the data

Any suggestions
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Setting Range in Graph

I would most likely use a Dynamic Named range instead. See Debra Dalgleish's
site:
http://www.contextures.com/xlNames01.html

For a VBA solution:

Dim cht As Chart
Dim lastrow As Long

lastrow = Range("B4").End(xlDown).Row
Set cht = ActiveSheet.ChartObjects("Chart 4").Chart
With cht
.SeriesCollection(1).Values = Range("B4:B" & lastrow)
.SeriesCollection(2).Values = Range("C4:C" & lastrow)
.SeriesCollection(3).Values = Range("I4:I" & lastrow)
End With

Regards,
Greg


"Nigel" wrote:

I have a worksheet called graphdata and another called charts. on the charts
worksheet there is chart 4. I am trying to dynamically set the range for the
chart as follows

Sheets("Charts").Activate
Range("A1").Select
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "=GraphData!$B$4:$B" & lastrow
ActiveChart.SeriesCollection(2).Values = "=GraphData!$C$4:$C" & lastrow
ActiveChart.SeriesCollection(3).Values = "=GraphData!$I$4:$i" & lastrow

lastrow is determined by using another and in this particular case is 34.

the actual chart series reads

=GraphData!$B$4:$B$32 and its that last number I want to dynamically change
depending on the number of rows in the data

Any suggestions

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting a formula = to no point in a graph jxbeeman Excel Discussion (Misc queries) 3 October 21st 08 10:04 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
setting range().hidden=True causes range error 1004 STEVE BELL Excel Programming 6 September 2nd 05 02:16 AM
Setting up data for a line graph cybrhound2 Charts and Charting in Excel 0 May 4th 05 02:51 PM
Setting a Range Tempy Excel Programming 6 June 15th 04 03:46 PM


All times are GMT +1. The time now is 11:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"