PC Review


Reply
Thread Tools Rate Thread

Charting in a loop

 
 
Otto Moehrbach
Guest
Posts: n/a
 
      13th Dec 2006
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 Where:=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 With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      13th Dec 2006
Union worked just fine in this simple procedure:

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 Where:=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 With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      13th Dec 2006
Jon
Thanks for that. I'll try it and see. Otto
"Jon Peltier" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Union worked just fine in this simple procedure:
>
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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 Where:=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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Simple window application with a loop and a button to eventuallystop the loop Joe Cool Microsoft C# .NET 15 29th Jul 2009 08:40 PM
returning back to loop check condition without completing the loop ashish128 Microsoft Excel Programming 13 3rd Apr 2008 12:53 PM
loop through field names, then use to loop through records topopulate grid pmacdiddie@gmail.com Microsoft Access Form Coding 1 4th Jan 2008 01:13 PM
Custom charting - Stacked charting with a line Randy Lefferts Microsoft Excel Charting 3 3rd Mar 2005 03:10 AM
Convert loop with Match function to avoid nested loop??? Kobayashi Microsoft Excel Programming 2 17th Mar 2004 06:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:00 AM.