Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Change data range in charts

I would like to copy a chart that already exists and change the data range to
show a different set of data. I used the record macro tool and it shows me
what I basically want to do. The problem is I need to change the "R" value so
I think I need to use a variable of some sort but the ways I have been doing
it doesn't work. Here is the sample I recorded:

Sub test()
'
' test Macro
'

'
Sheets("216-3").Select
Sheets("216-3").Copy Befo=Sheets(1)
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "=Data!R6735C4:R6786C4"
ActiveChart.SeriesCollection(2).Values = "=Data!R6735C5:R6786C5"
ActiveChart.SeriesCollection(3).Values = "=Data!R6735C9:R6786C9"
ActiveChart.SeriesCollection(4).Values = "=Data!R6735C11:R6786C11"

End Sub

I am going to put this in a loop to create mulitple charts but I need to
change the R6735 to R6818 as an example but as I mentioned, I am having a
problem with making a variable work in this situation. If anyone has a
suggestion I would appreciate it. Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Change data range in charts

You don't tell where those new values of R are coming from so I will assume
you have them stored in variables, e.g. R1 and R2, that are either integer
values or strings. Then it would be:
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "=Data!R" & R1 & "C4:R" & R2 &"C4"
ActiveChart.SeriesCollection(2).Values = "=Data!R" & R1 & "C4:R" & R2 &"C5"
ActiveChart.SeriesCollection(3).Values = "=Data!R" & R1 & "C4:R" & R2 & "C9"
ActiveChart.SeriesCollection(4).Values = "=Data!R" & R1 & "C4:R" & R2 &"C11"


"Tony" wrote:

I would like to copy a chart that already exists and change the data range to
show a different set of data. I used the record macro tool and it shows me
what I basically want to do. The problem is I need to change the "R" value so
I think I need to use a variable of some sort but the ways I have been doing
it doesn't work. Here is the sample I recorded:

Sub test()
'
' test Macro
'

'
Sheets("216-3").Select
Sheets("216-3").Copy Befo=Sheets(1)
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "=Data!R6735C4:R6786C4"
ActiveChart.SeriesCollection(2).Values = "=Data!R6735C5:R6786C5"
ActiveChart.SeriesCollection(3).Values = "=Data!R6735C9:R6786C9"
ActiveChart.SeriesCollection(4).Values = "=Data!R6735C11:R6786C11"

End Sub

I am going to put this in a loop to create mulitple charts but I need to
change the R6735 to R6818 as an example but as I mentioned, I am having a
problem with making a variable work in this situation. If anyone has a
suggestion I would appreciate it. Thank you in advance.

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
change range for multiple charts Yossi evenzur[_2_] Charts and Charting in Excel 2 December 9th 09 02:30 AM
Cannot change data source for copied charts MrN Charts and Charting in Excel 1 May 6th 09 05:59 PM
change source data in multiple charts Tuxla Charts and Charting in Excel 5 September 4th 08 03:38 PM
Can charts automatically change by entering new range of dates Sean Moor[_2_] Charts and Charting in Excel 17 June 17th 08 06:26 PM
In charts, is it possible to change data references to relevant? * B e X * Charts and Charting in Excel 1 May 22nd 07 02:00 PM


All times are GMT +1. The time now is 04:32 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"