+ Reply to Thread
Results 1 to 3 of 3

Works when stepped-through, but errors when macro ran

  1. #1

    Works when stepped-through, but errors when macro ran

    I use the following code to create a line chart. This is a small part
    of a much larger macro. In fact, it is but a small part of a
    subroutine that is called by an even larger subroutine. The problem is
    in referencing the source data for the chart.

    Worksheets("Baseline Data").Activate
    LastBase = Worksheets("Baseline
    Data").Range("A10").End(xlToRight).Column
    '
    Charts.Add
    ActiveChart.ChartType = xlXYScatterLines
    With ActiveChart
    .SeriesCollection.NewSeries
    .SeriesCollection(1).XValues = "='Baseline Data'!R10C2:R10C" &
    (LastBase - 1)
    .SeriesCollection(1).Values = "='Baseline Data'!R54C2:R54C" &
    (LastBase - 1)
    .SeriesCollection(1).Name = "=""Baseline"""
    .SeriesCollection(1).Border.Weight = xlThick

    When I run the subroutines, the reference to the "Baseline Data" sheet
    doesn't come through. That is the chart source data is
    =#REF!R10C11:R10C16. Interestingly, when I step through the code it
    works.

    Any thoughts?

    Thanks,
    John


  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Have you tried declaring all your variables? This sometimes helps when step through and run behave differently. Not completely sure why....
    Martin

  3. #3
    Bob Flanagan
    Guest

    Re: Works when stepped-through, but errors when macro ran

    John, make certain you have application.screenupdating = true as some chart
    statements only work when it is true. When you are stepping throught the
    code, screenupdating is always on, thus the reason it works in step through
    mode.

    Bob Flanagan
    Macro Systems
    144 Dewberry Drive
    Hockessin, Delaware, U.S. 19707

    Phone: 302-234-9857, cell 302-584-1771
    http://www.add-ins.com
    Productivity add-ins and downloadable books on VB macros for Excel

    <[email protected]> wrote in message
    news:[email protected]...
    >I use the following code to create a line chart. This is a small part
    > of a much larger macro. In fact, it is but a small part of a
    > subroutine that is called by an even larger subroutine. The problem is
    > in referencing the source data for the chart.
    >
    > Worksheets("Baseline Data").Activate
    > LastBase = Worksheets("Baseline
    > Data").Range("A10").End(xlToRight).Column
    > '
    > Charts.Add
    > ActiveChart.ChartType = xlXYScatterLines
    > With ActiveChart
    > .SeriesCollection.NewSeries
    > .SeriesCollection(1).XValues = "='Baseline Data'!R10C2:R10C" &
    > (LastBase - 1)
    > .SeriesCollection(1).Values = "='Baseline Data'!R54C2:R54C" &
    > (LastBase - 1)
    > .SeriesCollection(1).Name = "=""Baseline"""
    > .SeriesCollection(1).Border.Weight = xlThick
    >
    > When I run the subroutines, the reference to the "Baseline Data" sheet
    > doesn't come through. That is the chart source data is
    > =#REF!R10C11:R10C16. Interestingly, when I step through the code it
    > works.
    >
    > Any thoughts?
    >
    > Thanks,
    > John
    >




+ 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