Results 1 to 3 of 3

Thread: Multiple Charts

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Multiple Charts

    I have a fairly large data set (21000 rows) and i'm trying to write a macro to plot each set of 1000 points. So far my macro goes through once perfectly, but each subsequent graph is the same as the first. I know that the first series starts on row 7 and goes to 1006, the next starts at 1008 and goes to 2007 and so on, but each time I run this there will be a different number of series so I don't want to have it static. I've stepped through the code and this line doesn't update through each iteration.

    aaaCell = Cells(aaaRow, aaaColumn).Address

    Here is the loop part:

    While aaaRow < myLastRow
    bbbRow = aaaRow + 999
    aaaCell = Cells(aaaRow, aaaColumn).Address
    bbbCell = Cells(bbbRow, aaaColumn).Address
    myrange = aaaCell & ":" & bbbCell
    aaaRow = aaaRow + 1001
    Charts.Add
    ActiveChart.ChartType = xlXYScatterSmooth
    ActiveChart.SetSourceData Source:=Sheets("0070JUL132006@0944").Range( _
    myrange)
    ActiveChart.Location Where:=xlLocationAsObject, Name:="0070JUL132006@0944"

    Wend


    What is interesting, is if I comment out just the Charts.Add line, and step through, the cell range updates fine, but when it charts then, it just charts the first one over and over. Is there a probelm with have a Chart.Add in a loop? Whats the best way to do that?

    Thanks

    Joe Mac

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Multiple Charts

    Welcome to the forums.

    I ran the following small scale prototype of what you are doing and it works ok. There are 12 rows of data (rows 1-12) and 6 columns (A-F). Each plot contains 3 rows of data for a total of 4 charts.

    VB Code:
    1. Sub ChartTest()
    2.     Dim aaaRow As Integer, bbbRow As Integer, incr As Integer, myLastRow As Integer
    3.     Dim myRange As String
    4.     incr = 2
    5.     aaaRow = 0
    6.     bbbRow = 0
    7.     myLastRow = 10
    8.    
    9.     While aaaRow < myLastRow
    10.         aaaRow = bbbRow + 1
    11.         bbbRow = aaaRow + incr
    12.         myRange = "A" & aaaRow & ":F" & bbbRow
    13.         Charts.Add
    14.         With ActiveChart
    15.             .ChartType = xlXYScatterSmooth
    16.             .SetSourceData Source:=Sheets("Sheet1").Range(myRange)
    17.             .Location Where:=xlLocationAsObject, Name:="Sheet1"
    18.         End With
    19.     Wend
    20. End Sub
    Last edited by VBAhack; Jul 17th, 2006 at 03:48 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Re: Multiple Charts

    Awesome. So it appears that my cell creation was cr@p trying to use Cells(row, column).Address instead of just "e" & row. Thanks for the help.

    God Bless

    Joe Mac

Posting Permissions

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



Click Here to Expand Forum to Full Width