Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do i change the graph source data to a variable dependent on the value in a cell


My problem is to do with the data that my graph uses and making it
variable.

I'm writing a program that models the trajectory of a golf ball (a lot
more complicated than it sounds) using macros in excel. The outputs of
the program are deposited in columns, the first of which is dependent
on the value in a cell. For example if the value in the cell is 4 then
the data will start depositing in long columns from column D. This
enables several sets of data to be laid down alongside each other. This
part of the program works fine.

In addition to this I have, using macro recorder, set up a button and
related macro to draw and format a graph to show the trajectory. This
is also working fine.

What I want to be able to do is plot the graphs using the value in a
given cell as a pointer for the source data of the column. So far I
have read in the value from the cell and stored it as a variable,
'col'. The problem lies in that I don't know how to change the set
column references (C4 and C5) to variable ones (something like col and
col+1).


ActiveChart.SeriesCollection(1).XValues = "=Sheet1!C4"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!C5"

This is probably really simple to solve so please forgive my ignorance-
I'm only new to vba.

Many thanks

Steve Flanagan
icemonkeysteve


--
icemonkeysteve
------------------------------------------------------------------------
icemonkeysteve's Profile: http://www.excelforum.com/member.php...fo&userid=1681
View this thread: http://www.excelforum.com/showthread...hreadid=152891

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do i change the graph source data to a variable dependent on the value in a cell

Sub ChangeY_Values()

Dim rng As Range
Set rng = Range("B4:B10").Offset(0, Range("A1").Value)
sRange = "='" & ActiveSheet.Name & "'!" & rng.Address(1, 1, xlR1C1)
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).Values = sRange
End Sub


Worked for me. I used B4:B10 as a base range with other series in the same
rows to the right. I put the number of columns to offset in cell A1.

--
Regards,
Tom Ogilvy

icemonkeysteve wrote in message
...

My problem is to do with the data that my graph uses and making it
variable.

I'm writing a program that models the trajectory of a golf ball (a lot
more complicated than it sounds) using macros in excel. The outputs of
the program are deposited in columns, the first of which is dependent
on the value in a cell. For example if the value in the cell is 4 then
the data will start depositing in long columns from column D. This
enables several sets of data to be laid down alongside each other. This
part of the program works fine.

In addition to this I have, using macro recorder, set up a button and
related macro to draw and format a graph to show the trajectory. This
is also working fine.

What I want to be able to do is plot the graphs using the value in a
given cell as a pointer for the source data of the column. So far I
have read in the value from the cell and stored it as a variable,
'col'. The problem lies in that I don't know how to change the set
column references (C4 and C5) to variable ones (something like col and
col+1).


ActiveChart.SeriesCollection(1).XValues = "=Sheet1!C4"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!C5"

This is probably really simple to solve so please forgive my ignorance-
I'm only new to vba.

Many thanks

Steve Flanagan
icemonkeysteve


--
icemonkeysteve
------------------------------------------------------------------------
icemonkeysteve's Profile:

http://www.excelforum.com/member.php...fo&userid=1681
View this thread: http://www.excelforum.com/showthread...hreadid=152891



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do i change the graph source data to a variable dependent on the value in a cell

Cheers for that Tom- I should be able to use a similar idea for my
project.

Thanks once again!!

Steve



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

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
Graph where source data has different dates Chas Charts and Charting in Excel 1 October 2nd 08 12:43 PM
Change Source Data in a Graph James D. Sheehan Excel Discussion (Misc queries) 1 August 24th 07 02:10 AM
Variable Names in Source Data References in Charts Teflon TA Charts and Charting in Excel 2 January 21st 07 05:46 AM
Data Source for excel graph prakash Excel Discussion (Misc queries) 1 September 13th 06 09:38 AM
1-variable Data Table dependent on MS Query fails to update correctly [email protected] Excel Discussion (Misc queries) 0 March 30th 05 07:43 PM


All times are GMT +1. The time now is 04:41 AM.

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"