Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default How to set Chart SetSourceData in code..?

I have...

Worksheet("Sheet1")
r1, c1, r2, c2 As Integer

r1 = 24: c1 = 2: r2 = 68: c2 = 2

Charts("Chart1").SeriesCollection(1).Values =
Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))

r1 & r2 will change according to user interaction in other code.
What have i missed..?

Any help would be greatly appreciated. ;)



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How to set Chart SetSourceData in code..?

Just noticed this

Charts("Chart1").SeriesCollection(1).Values =
Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))

If Sheets1 isn't the active sheet, you may have problems with the Cells
piece since it's pointing to the active sheet.

"Andrew" wrote:

I have...

Worksheet("Sheet1")
r1, c1, r2, c2 As Integer

r1 = 24: c1 = 2: r2 = 68: c2 = 2

Charts("Chart1").SeriesCollection(1).Values =
Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))

r1 & r2 will change according to user interaction in other code.
What have i missed..?

Any help would be greatly appreciated. ;)




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default How to set Chart SetSourceData in code..?

Made sure Sheet is active..

Runtime Error '9':
Subscript out of range

Nice try though Barb..!

"Barb Reinhardt" wrote in
message ...
| Just noticed this
|
| Charts("Chart1").SeriesCollection(1).Values =
| Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))
|
| If Sheets1 isn't the active sheet, you may have problems with the
Cells
| piece since it's pointing to the active sheet.
|
| "Andrew" wrote:
|
| I have...
|
| Worksheet("Sheet1")
| r1, c1, r2, c2 As Integer
|
| r1 = 24: c1 = 2: r2 = 68: c2 = 2
|
| Charts("Chart1").SeriesCollection(1).Values =
| Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))
|
| r1 & r2 will change according to user interaction in other code.
| What have i missed..?
|
| Any help would be greatly appreciated. ;)
|
|
|
|


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How to set Chart SetSourceData in code..?

I don't do this often, so you may want to look here for ideas

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

HTH,
Barb Reinhardt

"Andrew" wrote:

Made sure Sheet is active..

Runtime Error '9':
Subscript out of range

Nice try though Barb..!

"Barb Reinhardt" wrote in
message ...
| Just noticed this
|
| Charts("Chart1").SeriesCollection(1).Values =
| Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))
|
| If Sheets1 isn't the active sheet, you may have problems with the
Cells
| piece since it's pointing to the active sheet.
|
| "Andrew" wrote:
|
| I have...
|
| Worksheet("Sheet1")
| r1, c1, r2, c2 As Integer
|
| r1 = 24: c1 = 2: r2 = 68: c2 = 2
|
| Charts("Chart1").SeriesCollection(1).Values =
| Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))
|
| r1 & r2 will change according to user interaction in other code.
| What have i missed..?
|
| Any help would be greatly appreciated. ;)
|
|
|
|



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to set Chart SetSourceData in code..?

Subscript out of range means that you're trying to use something that doesn't
exist.

Is there a worksheet named "Sheet1"?
Is there a chart named "Chart1"?




Andrew wrote:

Made sure Sheet is active..

Runtime Error '9':
Subscript out of range

Nice try though Barb..!

"Barb Reinhardt" wrote in
message ...
| Just noticed this
|
| Charts("Chart1").SeriesCollection(1).Values =
| Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))
|
| If Sheets1 isn't the active sheet, you may have problems with the
Cells
| piece since it's pointing to the active sheet.
|
| "Andrew" wrote:
|
| I have...
|
| Worksheet("Sheet1")
| r1, c1, r2, c2 As Integer
|
| r1 = 24: c1 = 2: r2 = 68: c2 = 2
|
| Charts("Chart1").SeriesCollection(1).Values =
| Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))
|
| r1 & r2 will change according to user interaction in other code.
| What have i missed..?
|
| Any help would be greatly appreciated. ;)
|
|
|
|


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How to set Chart SetSourceData in code..?

Try it with a continuous range and see if that works. If it does, that's
your problem.

"Andrew" wrote:

I have...

Worksheet("Sheet1")
r1, c1, r2, c2 As Integer

r1 = 24: c1 = 2: r2 = 68: c2 = 2

Charts("Chart1").SeriesCollection(1).Values =
Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))

r1 & r2 will change according to user interaction in other code.
What have i missed..?

Any help would be greatly appreciated. ;)




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to set Chart SetSourceData in code..?

I'd try:

with worksheets("Sheet1")
Charts("Chart1").SeriesCollection(1).Values _
= .Range(.Cells(r1, c1), .Cells(r2,c2)).value
end with

If the code is behind a worksheet, then those unqualifed ranges won't refer to
the activesheet--they'll refer to the sheet that owns the code.


Andrew wrote:

I have...

Worksheet("Sheet1")
r1, c1, r2, c2 As Integer

r1 = 24: c1 = 2: r2 = 68: c2 = 2

Charts("Chart1").SeriesCollection(1).Values =
Worksheets("Sheet1").Range(Cells(r1, c1), Cells(r2,c2))

r1 & r2 will change according to user interaction in other code.
What have i missed..?

Any help would be greatly appreciated. ;)


--

Dave Peterson
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
I think the problem is in .SetSourceData ?? keith Excel Programming 2 April 20th 09 12:53 PM
setSourcedata tony wong Excel Programming 2 February 22nd 07 02:06 PM
Series.Values vs Chart.SetSourceData Hans Excel Programming 2 January 20th 06 11:19 AM
SetSourceData for Chart Doerte Excel Programming 2 November 29th 04 11:55 AM


All times are GMT +1. The time now is 03:35 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"