+ Reply to Thread
Results 1 to 5 of 5

Source data for chart

  1. #1
    Forum Contributor
    Join Date
    08-22-2005
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    349

    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

  2. #2
    Jon Peltier
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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
    >




  3. #3

    Re: 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 Where:=xlLocationAsObject, Name:="Sheet1"


  4. #4
    Jon Peltier
    Guest

    Re: 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 Where:=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/
    _______


    <[email protected]> wrote in message
    news:[email protected]...
    >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 Where:=xlLocationAsObject, Name:="Sheet1"
    >




  5. #5
    Forum Contributor
    Join Date
    08-22-2005
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    349
    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 I can do with the other example.

    NSV

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1