+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Trouble with adding dynamic chart

    I am using the code below to add a chart using a dynamic row length. However teh chart keeps skipping over the data in column B and does not include it in the chart. Also, the chart begins with a date that is not in the data range-how can I make that correspond to the data range?
    Any ideas on why column B is being skipped?

    Code:
    Dim charrange As Range
    Set charrange = Range("a4:a65536")
    Dim lastcharrow As Long
    With charrange
        lastcharrow = charrange.Find("*", [a4], xlValues, xlPart, xlByRows, xlPrevious).Row
    End With
    Range(Cells(3, 1), Cells(lastcharrow, 6)).Select
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.SetSourceData Source:=ActiveSheet.Range(Cells(3, 1), Cells(lastcharrow, 6))
        ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
        ActiveChart.SeriesCollection(1).Delete
        With ActiveChart.Parent
            .Left = 100
            .Width = 500
            .Top = 50
            .Height = 300
        End With
    Last edited by nsorden; 08-12-2009 at 10:54 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Trouble with adding dynamic chart

    can you post example of your data layout.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Trouble with adding dynamic chart

    I am an idiot. The line
    Code:
        ActiveChart.SeriesCollection(1).Delete
    was eliminating the column B data. I have also been able to set the axes limits to correspond to ranges.

    The following code enables dynamic axis ranges. Where chrtd is the sheet name and the respective cells contain max and min formulas for the data range.

    Code:
        ActiveChart.Axes(xlCategory).MinimumScale = chrtd.Range("e2")
        ActiveChart.Axes(xlCategory).MaximumScale = chrtd.Range("f2")
        ActiveChart.Axes(xlValue).MinimumScale = chrtd.Range("b2")
        ActiveChart.Axes(xlValue).MaximumScale = chrtd.Range("c2")

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.2.0