Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Charting in a loop

Excel XP, Win XP
I have 14 rows of data I want to chart, each row in a different chart.
The following code charts row 1 as the "X" axis and the values in row 2 as
the "Y" axis. Good.
Sub TestChart()
Range("C1:R2").Select
Charts.Add
ActiveChart.SetSourceData Source:=Sheets("By store").Range("C1:R2")
ActiveChart.Location Whe=xlLocationAsNewSheet
End Sub
This code creates only one chart, as expected.
But I want to create charts of row 1 versus each of the other rows (13
charts).
I've tried a loop through all the rows using a Union of row 1 and each other
row as the range. Didn't work.
I know I can copy row 1 and each of the other rows, in turn, to a Utility
sheet, and chart that.
My question: How can I create the 13 charts without resorting to the Utility
sheet method?
Thanks for your time. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Charting in a loop

Union worked just fine in this simple procedu

Sub ChartEachRow()
Dim iRow As Long
Dim cht As Chart
Dim rng As Range
Dim wks As Worksheet

Set wks = ActiveSheet
For iRow = 2 To 14
Set rng = Union(wks.Range("C1:R1"), wks.Range("C" & iRow & ":R" & iRow))
Set cht = ActiveWorkbook.Charts.Add
cht.SetSourceData Source:=rng
Next
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Otto Moehrbach" wrote in message
...
Excel XP, Win XP
I have 14 rows of data I want to chart, each row in a different chart.
The following code charts row 1 as the "X" axis and the values in row 2 as
the "Y" axis. Good.
Sub TestChart()
Range("C1:R2").Select
Charts.Add
ActiveChart.SetSourceData Source:=Sheets("By store").Range("C1:R2")
ActiveChart.Location Whe=xlLocationAsNewSheet
End Sub
This code creates only one chart, as expected.
But I want to create charts of row 1 versus each of the other rows (13
charts).
I've tried a loop through all the rows using a Union of row 1 and each
other row as the range. Didn't work.
I know I can copy row 1 and each of the other rows, in turn, to a Utility
sheet, and chart that.
My question: How can I create the 13 charts without resorting to the
Utility sheet method?
Thanks for your time. Otto



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Charting in a loop

Jon
Thanks for that. I'll try it and see. Otto
"Jon Peltier" wrote in message
...
Union worked just fine in this simple procedu

Sub ChartEachRow()
Dim iRow As Long
Dim cht As Chart
Dim rng As Range
Dim wks As Worksheet

Set wks = ActiveSheet
For iRow = 2 To 14
Set rng = Union(wks.Range("C1:R1"), wks.Range("C" & iRow & ":R" &
iRow))
Set cht = ActiveWorkbook.Charts.Add
cht.SetSourceData Source:=rng
Next
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Otto Moehrbach" wrote in message
...
Excel XP, Win XP
I have 14 rows of data I want to chart, each row in a different chart.
The following code charts row 1 as the "X" axis and the values in row 2
as the "Y" axis. Good.
Sub TestChart()
Range("C1:R2").Select
Charts.Add
ActiveChart.SetSourceData Source:=Sheets("By store").Range("C1:R2")
ActiveChart.Location Whe=xlLocationAsNewSheet
End Sub
This code creates only one chart, as expected.
But I want to create charts of row 1 versus each of the other rows (13
charts).
I've tried a loop through all the rows using a Union of row 1 and each
other row as the range. Didn't work.
I know I can copy row 1 and each of the other rows, in turn, to a Utility
sheet, and chart that.
My question: How can I create the 13 charts without resorting to the
Utility sheet method?
Thanks for your time. Otto





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
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Custom charting - Stacked charting with a line Randy Lefferts Charts and Charting in Excel 3 March 3rd 05 03:10 AM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


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

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"