Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SetSourceData for Chart

Hi,

I need to add many charts to an Excel Worksheet. The data are based in
columns.
Basically, I need a separate chart for every 10 entries.

I was hoping to be able to set the data source with the follwing code:

ActiveChart.SetSourceData Source:=Sheets("RTK_Comp").Range(Cells(7 + i, 30),
Cells(16 + i, 30)), PlotBy:=xlColumns

I get this run-time error: Method "Cells" of object "_Global" failed.

Has anybody any idea where I have been going wrong?

The full code is:

Sub draw_charts()

Worksheets("RTK_Comp").Activate
counter1 = 0

Do
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("RTK_Comp").Range(Cells(7 +
counter1, 30), Cells(16 + counter1, 30)), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues =
Worksheets("RTK_Comp").Range(Cells(7 + counter1, 25), Cells(16 + counter1,
25))
ActiveChart.Location Whe=xlLocationAsObject, Name:="RTK_Comp"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Test Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "GPS Seconds"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Error [m]"
End With
counter1 = counter1 + 10
Loop Until ActiveSheet.Cells(7 + counter1, 25).Value = ""

End Sub


Thanks a lot,
Doerte
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default SetSourceData for Chart

If the worksheet RTK_Comp is not the active sheet when the code
is executed, you need to qualify the Cells property with the
worksheet name. For simplicity, use the With statement:


With Sheets("RTK_Comp")
ActiveChart.SetSourceData Source:=
..Range(.Cells(7+i,30),.Cells(16+i,30), _
PlotBy:=xlColumns
End With

Note the leading periods before Range and Cells.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Doerte" wrote in message
...
Hi,

I need to add many charts to an Excel Worksheet. The data are
based in
columns.
Basically, I need a separate chart for every 10 entries.

I was hoping to be able to set the data source with the
follwing code:

ActiveChart.SetSourceData
Source:=Sheets("RTK_Comp").Range(Cells(7 + i, 30),
Cells(16 + i, 30)), PlotBy:=xlColumns

I get this run-time error: Method "Cells" of object "_Global"
failed.

Has anybody any idea where I have been going wrong?

The full code is:

Sub draw_charts()

Worksheets("RTK_Comp").Activate
counter1 = 0

Do
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData
Source:=Sheets("RTK_Comp").Range(Cells(7 +
counter1, 30), Cells(16 + counter1, 30)), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues =
Worksheets("RTK_Comp").Range(Cells(7 + counter1, 25), Cells(16
+ counter1,
25))
ActiveChart.Location Whe=xlLocationAsObject,
Name:="RTK_Comp"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Test Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"GPS Seconds"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"Error [m]"
End With
counter1 = counter1 + 10
Loop Until ActiveSheet.Cells(7 + counter1, 25).Value = ""

End Sub


Thanks a lot,
Doerte



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SetSourceData for Chart

Thanks Chip. This did the trick.

Doerte

"Chip Pearson" wrote:

If the worksheet RTK_Comp is not the active sheet when the code
is executed, you need to qualify the Cells property with the
worksheet name. For simplicity, use the With statement:


With Sheets("RTK_Comp")
ActiveChart.SetSourceData Source:=
..Range(.Cells(7+i,30),.Cells(16+i,30), _
PlotBy:=xlColumns
End With

Note the leading periods before Range and Cells.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Doerte" wrote in message
...
Hi,

I need to add many charts to an Excel Worksheet. The data are
based in
columns.
Basically, I need a separate chart for every 10 entries.

I was hoping to be able to set the data source with the
follwing code:

ActiveChart.SetSourceData
Source:=Sheets("RTK_Comp").Range(Cells(7 + i, 30),
Cells(16 + i, 30)), PlotBy:=xlColumns

I get this run-time error: Method "Cells" of object "_Global"
failed.

Has anybody any idea where I have been going wrong?

The full code is:

Sub draw_charts()

Worksheets("RTK_Comp").Activate
counter1 = 0

Do
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData
Source:=Sheets("RTK_Comp").Range(Cells(7 +
counter1, 30), Cells(16 + counter1, 30)), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues =
Worksheets("RTK_Comp").Range(Cells(7 + counter1, 25), Cells(16
+ counter1,
25))
ActiveChart.Location Whe=xlLocationAsObject,
Name:="RTK_Comp"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Test Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"GPS Seconds"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"Error [m]"
End With
counter1 = counter1 + 10
Loop Until ActiveSheet.Cells(7 + counter1, 25).Value = ""

End Sub


Thanks a lot,
Doerte




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
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Charts and Charting in Excel 2 March 6th 09 04:43 PM
SetSourceData for UserType XYChart with two series PBezucha Charts and Charting in Excel 2 February 18th 08 02:01 PM
defined names and setsourcedata Jason Morin Charts and Charting in Excel 2 December 5th 07 03:39 PM
charting problem with activechart.setsourcedata Mary Kathryn Excel Discussion (Misc queries) 4 February 25th 06 08:54 PM
Activechart.SetSourceData Source??? Bob R Excel Programming 2 July 30th 04 03:39 PM


All times are GMT +1. The time now is 06:59 AM.

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

About Us

"It's about Microsoft Excel"