+ Reply to Thread
Results 1 to 3 of 3

Please Help With Chart Code

  1. #1
    Registered User
    Join Date
    05-05-2005
    Posts
    10

    Please Help With Chart Code

    Hi. I am using Excel 2003.

    I used the macro recorder and modied some of the code in the hopes that the
    VBA I wrote work work. Instead, it produces errors. I have a Chart object on
    a Sheet that I wish to "feed" a range to chart. Since the number of rows for the
    needed range changes from time to time, I included a variable called amtrows.
    Then I try to "assign" a range to variable XTemp. Then I try to feed that XTemp
    range into the Chart object.

    My modified code errors at this line --

    Set XTemp = Sheets("Sheet5").Range("C1").Resize(amtrows, 1)

    And at these lines as well --

    ActiveChart.SetSourceData Source:= XTemp, PlotBy :=xlColumns
    ActiveChart.SeriesCollection(1).XValues = Range(TimeFrame)

    Could you please review my code below and tell me what to change ? I would be most
    grateful for your help. Thank you.

    WayneK

    Sub ModifyChart1()

    Dim amtrows As Long
    Dim XTemp As Range

    amtrows = Sheets("Sheet5").Range("A8").Value

    Set XTemp = Sheets("Sheet5").Range("C1").Resize(amtrows, 1)
    Set TimeRange = Sheets("Sheet3").Range("C7").Resize(amtrows, 1)

    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.ChartArea.Select
    ActiveChart.SetSourceData Source:= XTemp, PlotBy :=xlColumns
    ActiveChart.SeriesCollection(1).XValues = Range(TimeFrame)

    ActiveWindow.Visible = False

    Range("A1").Select

    End Sub
    Last edited by WayneK; 08-09-2005 at 10:08 AM. Reason: typos

  2. #2
    Registered User
    Join Date
    05-05-2005
    Posts
    10
    Does anyone have any ideas towards a solution ?

    Thank you.

    WayneK
    Last edited by WayneK; 08-09-2005 at 10:10 AM. Reason: typo

  3. #3
    Peter T
    Guest

    Re: Please Help With Chart Code

    Hi Wayne,

    Have a look at this line -

    Set XTemp = Range("C1").Resize(x, 0)

    Resize requires the row & column arguments each to be at least 1. Both yours
    are 0, as you have not assigned a value to x.

    You say "amtrows" is required but it's not used in your code.

    Subject to setting XTemp to a cell range that works with your chart type the
    rest of your code should work, but no need to select the chartarea.

    Regards,
    Peter T

    "WayneK" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi. I am using Excel 2003.
    >
    > I used the macro recorder and modied some of the code in the hopes that
    > the
    > VBA I wrote work work. Instead, it produces errors. I have a Chart
    > object on
    > a Sheet that I wish to "feed" a range to chart. Since the number of
    > rows for the
    > needed range changes from time to time, I included a variable called
    > amtrows.
    > Then I try to "assign" a range to variable XTemp. Then I try to feed
    > that XTemp
    > range into the Chart object.
    >
    > My modified code errors at this line --
    >
    > Set XTemp = Range("C1").Resize(x, 0)
    >
    > And at this line as well --
    >
    > ActiveChart.SetSourceData Source:=Sheets("Sheet5").Range(XTemp), PlotBy
    > _
    > :=xlColumns
    >
    > Could you please review my code below and tell me what to change ? I
    > would be most
    > grateful for your help.
    >
    > WayneK
    >
    > Dim amtrows As Long
    > Dim XTemp As Range
    >
    > amtrows = Range("A8").Value
    >
    > Set XTemp = Range("C1").Resize(x, 0)
    >
    > ActiveSheet.ChartObjects("Chart 2").Activate
    > ActiveChart.ChartArea.Select
    > ActiveChart.SetSourceData Source:=Sheets("Sheet5").Range(XTemp), PlotBy
    > _
    > :=xlColumns
    > ActiveWindow.Visible = False
    >
    >
    > --
    > WayneK
    > ------------------------------------------------------------------------
    > WayneK's Profile:

    http://www.excelforum.com/member.php...o&userid=23037
    > View this thread: http://www.excelforum.com/showthread...hreadid=394173
    >




+ 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