Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default chart range to include variables - Macro

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("D2:D5")
ActiveChart.SeriesCollection(1).Values = Sheets("For
Plots").Range("A2:A5")
ActiveChart.SeriesCollection(1).Name = "='For Plots'!R2C2"
ActiveChart.Location Whe=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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default chart range to include variables - Macro

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("D2:D5")
ActiveChart.SeriesCollection(1).Values = Sheets("For
Plots").Range("A2:A5")
ActiveChart.SeriesCollection(1).Name = "='For Plots'!R2C2"
ActiveChart.Location Whe=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
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
Only Include Last Four Entries in a Chart asmithbcat Excel Discussion (Misc queries) 1 June 18th 09 11:50 PM
Include line chart in 3 d bar chart Anton Charts and Charting in Excel 6 June 6th 09 10:39 AM
Storing variables in a macro and using those variables to performcalculations. [email protected] Excel Programming 3 December 10th 07 04:13 PM
Passing variables for range series charts, what to do with post macro run; unable to osman[_3_] Excel Programming 1 May 21st 06 04:07 PM
range variables for chart x axis values gvm Excel Programming 2 November 18th 05 05:15 AM


All times are GMT +1. The time now is 04:24 PM.

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

About Us

"It's about Microsoft Excel"