PC Review


Reply
Thread Tools Rate Thread

Charting with dynamic data

 
 
=?Utf-8?B?Sm9u?=
Guest
Posts: n/a
 
      16th Feb 2005
All,
I am creating a chart which is based on multiple columns worth of data.
The problem is that the amount of rows changes and I have to be able to
handle that programmaticaly. In other words, if the amount of rows was
constant somewhere in my sub I would have something like:

..Chart.SetSourceData Source:=Sheets("NameGoesHere").Range("A2:A5, F2:H5")

'where the Range A2:A5 contains names that goes to label the X-axis.
'And F2:H5 represents the data for each name in A2:A5. No problem.

However, I need that range to vary. I was hoping something like this would
work:

.Chart.ChartWizard
Source:=Worksheets(xlSheet(I).Name).Range(xlSheet(I).Cells(2,
1):xlSheet(I).Cells(z, 1), xlSheet(I).Cells(2, 6):xlSheet(I).Cells(z, 8))

'where z is an integer which calculated the number of rows needed. Problem.
'Didn't work

As you can see I tried to mimic the form used for static data but failed
miserably. Any help would be greatly appreciated. Clear as mud? Thanks in
advance.


--
J
 
Reply With Quote
 
 
 
 
Markus Scheible
Guest
Posts: n/a
 
      17th Feb 2005
Hi Jon,

I would try another procedure: Link the chart with a named
range, e.g.

..Chart.SetSourceData Source:=Sheets("NameGoesHere").Range
("arguments")

Then you can name the arguments range, starting at a known
cell e.g. A2 and down all filled rows with:

..Range("A2", "A" & .Range("A2", "A65534").SpecialCells
(xlCellTypeBlanks).Cells(1).Row - 1).Name = "data"

For info: xlCellTypeBlanks gives you the first empty cell,
therefore you need to use .Row - 1


Best

Markus
 
Reply With Quote
 
=?Utf-8?B?Sm9u?=
Guest
Posts: n/a
 
      17th Feb 2005
Markus,
Thanks for the quick response. I see exactly what you are trying, but I
cannot get my code to run with it. Here's the relevant snippet, tell me if
this is what you had in mind.

Set ch = Worksheets("Charts").ChartObjects.Add(Left:=15, Width:=700, _
Top:=(J * (225 + 25) + 50), Height:=225)
With ch
.Chart.SetSourceData Source:=Sheets(xlSheet(I).Name).Range(xlSheet(I). _
Cells(2, 6), xlSheet(I).Cells(z, 8))
.Chart.Range("A2", "A" & .Range("A2", "A65534").SpecialCells _
(xlCellTypeBlanks).Cells(1).Row - 1).Name = "data"
End With

I end up with a run-time error 438 "Object doesn't support this property or
method"

What am I missing here?

"Markus Scheible" wrote:

> Hi Jon,
>
> I would try another procedure: Link the chart with a named
> range, e.g.
>
> ..Chart.SetSourceData Source:=Sheets("NameGoesHere").Range
> ("arguments")
>
> Then you can name the arguments range, starting at a known
> cell e.g. A2 and down all filled rows with:
>
> ..Range("A2", "A" & .Range("A2", "A65534").SpecialCells
> (xlCellTypeBlanks).Cells(1).Row - 1).Name = "data"
>
> For info: xlCellTypeBlanks gives you the first empty cell,
> therefore you need to use .Row - 1
>
>
> Best
>
> Markus
>

 
Reply With Quote
 
=?Utf-8?B?Sm9u?=
Guest
Posts: n/a
 
      17th Feb 2005
Anyone else have thoughts on this?

"Jon" wrote:

> All,
> I am creating a chart which is based on multiple columns worth of data.
> The problem is that the amount of rows changes and I have to be able to
> handle that programmaticaly. In other words, if the amount of rows was
> constant somewhere in my sub I would have something like:
>
> .Chart.SetSourceData Source:=Sheets("NameGoesHere").Range("A2:A5, F2:H5")
>
> 'where the Range A2:A5 contains names that goes to label the X-axis.
> 'And F2:H5 represents the data for each name in A2:A5. No problem.
>
> However, I need that range to vary. I was hoping something like this would
> work:
>
> .Chart.ChartWizard
> Source:=Worksheets(xlSheet(I).Name).Range(xlSheet(I).Cells(2,
> 1):xlSheet(I).Cells(z, 1), xlSheet(I).Cells(2, 6):xlSheet(I).Cells(z, 8))
>
> 'where z is an integer which calculated the number of rows needed. Problem.
> 'Didn't work
>
> As you can see I tried to mimic the form used for static data but failed
> miserably. Any help would be greatly appreciated. Clear as mud? Thanks in
> advance.
>
>
> --
> J

 
Reply With Quote
 
=?Utf-8?B?Sm9u?=
Guest
Posts: n/a
 
      17th Feb 2005
For all who are interested here is a snippet that provides the solution (I
have no hair now...). UNION was the key.

With ch

..Chart.ChartWizard Source:=Union( _
Worksheets(xlSheet(i).Name).Range(xlSheet(i).Cells(2, 1),
xlSheet(i).Cells(z, 1)), _
Worksheets(xlSheet(i).Name).Range(xlSheet(i).Cells(2, 6),
xlSheet(i).Cells(z, 8))), _
Title:=xlSheet(i).Name, _
PlotBy:=xlColumns, _
CategoryLabels:=1
End With

Thanks to all who thought about it.



"Jon" wrote:

> All,
> I am creating a chart which is based on multiple columns worth of data.
> The problem is that the amount of rows changes and I have to be able to
> handle that programmaticaly. In other words, if the amount of rows was
> constant somewhere in my sub I would have something like:
>
> .Chart.SetSourceData Source:=Sheets("NameGoesHere").Range("A2:A5, F2:H5")
>
> 'where the Range A2:A5 contains names that goes to label the X-axis.
> 'And F2:H5 represents the data for each name in A2:A5. No problem.
>
> However, I need that range to vary. I was hoping something like this would
> work:
>
> .Chart.ChartWizard
> Source:=Worksheets(xlSheet(I).Name).Range(xlSheet(I).Cells(2,
> 1):xlSheet(I).Cells(z, 1), xlSheet(I).Cells(2, 6):xlSheet(I).Cells(z, 8))
>
> 'where z is an integer which calculated the number of rows needed. Problem.
> 'Didn't work
>
> As you can see I tried to mimic the form used for static data but failed
> miserably. Any help would be greatly appreciated. Clear as mud? Thanks in
> advance.
>
>
> --
> J

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      18th Feb 2005
Jon -

You found something that works. This command in your earlier post must
have been causing major problems:

.Chart.Range("A2", "A" & .Range("A2", "A65534").SpecialCells _
(xlCellTypeBlanks).Cells(1).Row - 1).Name = "data"

Since a Chart has no Range method or property, the line can only lead to
run time errors.

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

Jon wrote:

> Markus,
> Thanks for the quick response. I see exactly what you are trying, but I
> cannot get my code to run with it. Here's the relevant snippet, tell me if
> this is what you had in mind.
>
> Set ch = Worksheets("Charts").ChartObjects.Add(Left:=15, Width:=700, _
> Top:=(J * (225 + 25) + 50), Height:=225)
> With ch
> .Chart.SetSourceData Source:=Sheets(xlSheet(I).Name).Range(xlSheet(I). _
> Cells(2, 6), xlSheet(I).Cells(z, 8))
> .Chart.Range("A2", "A" & .Range("A2", "A65534").SpecialCells _
> (xlCellTypeBlanks).Cells(1).Row - 1).Name = "data"
> End With
>
> I end up with a run-time error 438 "Object doesn't support this property or
> method"
>
> What am I missing here?
>
> "Markus Scheible" wrote:
>
>
>>Hi Jon,
>>
>>I would try another procedure: Link the chart with a named
>>range, e.g.
>>
>>..Chart.SetSourceData Source:=Sheets("NameGoesHere").Range
>>("arguments")
>>
>>Then you can name the arguments range, starting at a known
>>cell e.g. A2 and down all filled rows with:
>>
>>..Range("A2", "A" & .Range("A2", "A65534").SpecialCells
>>(xlCellTypeBlanks).Cells(1).Row - 1).Name = "data"
>>
>>For info: xlCellTypeBlanks gives you the first empty cell,
>>therefore you need to use .Row - 1
>>
>>
>>Best
>>
>>Markus
>>

 
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
Data Labels, Error Bars, and Dynamic Charting Rcarper Microsoft Excel Charting 1 28th Aug 2009 04:24 AM
dynamic charting brian.baker13@googlemail.com Microsoft Excel Discussion 0 10th Nov 2007 03:36 PM
Dynamic Charting Question re data PS Microsoft Excel Charting 4 20th Sep 2006 05:44 PM
Dynamic Charting - i think! jamie.rowland@shell.com Microsoft Excel Charting 4 27th Jul 2006 09:33 AM
Dynamic Charting - User Selected Data Lines mikluk Microsoft Excel Charting 1 1st Dec 2005 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:46 PM.