ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Source data for chart (https://www.excelbanter.com/excel-programming/346280-source-data-chart.html)

nsv[_7_]

Source data for chart
 

I have the following lines of code in a macro:

ActiveSheet.ChartObjects("Prob").Activate
ActiveChart.SeriesCollection(1).XValues = "=prob!R1C1:R45C1"
ActiveChart.SeriesCollection(1).Values = "=prob!R1C2:R45C2"

I want the number of chart data rows (in this example it is 45) to be
variable so that this value is taken from a cell in the sheet, but it
will not accept a variable name here.

Is this possible?


NSV


--
nsv
------------------------------------------------------------------------
nsv's Profile: http://www.excelforum.com/member.php...o&userid=26500
View this thread: http://www.excelforum.com/showthread...hreadid=487226


Jon Peltier

Source data for chart
 
I can't test it on this computer, but try:

RowNum = ActiveSheet.Range("D2").Value
ActiveSheet.ChartObjects("Prob").Activate
ActiveChart.SeriesCollection(1).XValues = "=prob!R1C1:R" & RowNum & "C1"
ActiveChart.SeriesCollection(1).Values = "=prob!R1C2:R" & RowNum & "C2"

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

"nsv" wrote in message
...

I have the following lines of code in a macro:

ActiveSheet.ChartObjects("Prob").Activate
ActiveChart.SeriesCollection(1).XValues = "=prob!R1C1:R45C1"
ActiveChart.SeriesCollection(1).Values = "=prob!R1C2:R45C2"

I want the number of chart data rows (in this example it is 45) to be
variable so that this value is taken from a cell in the sheet, but it
will not accept a variable name here.

Is this possible?


NSV


--
nsv
------------------------------------------------------------------------
nsv's Profile:
http://www.excelforum.com/member.php...o&userid=26500
View this thread: http://www.excelforum.com/showthread...hreadid=487226




[email protected]

Source data for chart
 
I have a similar question. In my case I want to highlight the xy
values for the chart, then chart the data on a scatter plot. The data
are surrounded by other populated columns - so CurrentRegion won't
work. The problem in the skinnied-down macro below is the Range
function takes the hard coded range. How do I pass in the
user-selected range?

Charts.Add
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B4:C10")
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"


Jon Peltier[_10_]

Source data for chart
 
Dim rSelection As Range
If TypeName(Selection) = "Range" Then
Set rSelection = Selection
Charts.Add
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SetSourceData Source:=rSelection
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
Else
MsgBox "Select a range and try again", vbCritical
Exit Sub
End If

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


wrote in message
ups.com...
I have a similar question. In my case I want to highlight the xy
values for the chart, then chart the data on a scatter plot. The data
are surrounded by other populated columns - so CurrentRegion won't
work. The problem in the skinnied-down macro below is the Range
function takes the hard coded range. How do I pass in the
user-selected range?

Charts.Add
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B4:C10")
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"




nsv[_8_]

Source data for chart
 

Thanks Jon, but it doesn't work. The compiler only reads:

ActiveChart.SeriesCollection(1).XValues = "=prob!R1C1:R"

and the rest of the line is turned into rubbish, but I will try what
can do with the other example.

NS

--
ns
-----------------------------------------------------------------------
nsv's Profile: http://www.excelforum.com/member.php...fo&userid=2650
View this thread: http://www.excelforum.com/showthread.php?threadid=48722



All times are GMT +1. The time now is 05:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com