PC Review


Reply
Thread Tools Rate Thread

chart range to include variables - Macro

 
 
Adam_needs_help
Guest
Posts: n/a
 
      14th Nov 2008
I am trying to write a macro that makes a bar chart. However the range for
the Xvalues and Values change each time it is run, so I want them to be
dependent on variables. The code below works but it not variable dependent.

Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("For Plots").Range("A1:E183"), _
PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = Sheets("For
Plots").Range("D25")
ActiveChart.SeriesCollection(1).Values = Sheets("For
Plots").Range("A2:A5")
ActiveChart.SeriesCollection(1).Name = "='For Plots'!R2C2"
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.HasLegend = False

I want something like:

ActiveChart.SeriesCollection(1).Values = Sheets("For
Plots").Range(Cells(1,2),Cells(1,5))

Because I can put variable names in the Cells() area. Is there another way
to do this? I am reading all sorts of posts and not finding this exactly.

Thanks for your help.
 
Reply With Quote
 
 
 
 
Adam_needs_help
Guest
Posts: n/a
 
      14th Nov 2008
Looks like I finally came across the right post. Here is the solution:

Just compose the string in the format you've already got, using the &
operator to piece together the various components, along the lines of:
ActiveChart.SeriesCollection(1).XValues = "='Traffic model'!R" & StartRow &
"C" & StartCol & ":R" & EndRow & "C" & EndCol

link -
http://www.microsoft.com/office/comm...=en-us&m=1&p=1


"Adam_needs_help" wrote:

> I am trying to write a macro that makes a bar chart. However the range for
> the Xvalues and Values change each time it is run, so I want them to be
> dependent on variables. The code below works but it not variable dependent.
>
> Charts.Add
> ActiveChart.ChartType = xlColumnClustered
> ActiveChart.SetSourceData Source:=Sheets("For Plots").Range("A1:E183"), _
> PlotBy:=xlRows
> ActiveChart.SeriesCollection(1).XValues = Sheets("For
> Plots").Range("D25")
> ActiveChart.SeriesCollection(1).Values = Sheets("For
> Plots").Range("A2:A5")
> ActiveChart.SeriesCollection(1).Name = "='For Plots'!R2C2"
> ActiveChart.Location Where:=xlLocationAsNewSheet
> ActiveChart.HasLegend = False
>
> I want something like:
>
> ActiveChart.SeriesCollection(1).Values = Sheets("For
> Plots").Range(Cells(1,2),Cells(1,5))
>
> Because I can put variable names in the Cells() area. Is there another way
> to do this? I am reading all sorts of posts and not finding this exactly.
>
> Thanks for your help.

 
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
Change chart range with macro Greg Snidow Microsoft Excel Charting 1 27th Mar 2009 04:57 PM
using a macro to edit the data range of a chart Monkey-See, Monkey-Do Microsoft Excel Programming 2 29th Jun 2008 05:12 PM
Passing variables for range series charts, what to do with post macro run; unable to osman Microsoft Excel Programming 1 21st May 2006 04:07 PM
range variables for chart x axis values =?Utf-8?B?Z3Zt?= Microsoft Excel Programming 2 18th Nov 2005 05:15 AM
Dynamic Range Chart Macro Question GerbilGod7 Microsoft Excel Programming 6 16th Aug 2004 12:04 PM


Features
 

Advertising
 

Newsgroups
 


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