+ Reply to Thread
Results 1 to 5 of 5

Chart macro

Hybrid View

  1. #1
    Registered User
    Join Date
    02-11-2009
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Chart macro

    Hey everyone. I'm trying to make a scatterplot so what I did was recorded a macro and now I want to be able to update it using a for-loop. Here's my code.

    Charts.Add.Name = "Chart"
    ActiveChart.ChartType = xlXYScatterLines
    
    For counter2 = 2 To numEntries
    
         'Some other stuff right here
    
         If Cells(counter2, 1) <> Cells(counter2 + 1, 1) Then
                bool2 = False
                Sheets("Chart").Select
                ActiveChart.SeriesCollection.NewSeries
                With ActiveChart
                    .Name = ActiveSheet.Cells(position2, 1)
                    .Values = ActiveSheet.Range(position2 & "6:" & counter2 & "6")
                    .XValues = ActiveSheet.Range("A4:A14")
                End With
    
                
                Sheets("Temporary").Select
            End If
        Next
    My problem is with the three lines of .Name, .Values, and .XValues. When I run, I get a compile error of Method or Data Member Not Found.

    I need to be able to create a new series each time the if-statement is run through and change the name, y-vals, and x-vals of the series according to my variables of counter2 and position2. Help me please!
    Last edited by monk2211; 02-11-2009 at 10:05 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,456

    Re: Chart macro

    Try this

                with ActiveChart.SeriesCollection.NewSeries
                    .Name = ActiveSheet.Cells(position2, 1)
                    .Values = ActiveSheet.Range(position2 & "6:" & counter2 & "6")
                    .XValues = ActiveSheet.Range("A4:A14")
                End With
    If not post example workbook
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    02-11-2009
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Chart macro

    That fixed my compile error, but now I get a new one:

    Run-Time Error '438':
    Object doesn't support this property or method.

    Example workbook attached. Scroll down to the GRAPH comment.
    Last edited by monk2211; 02-11-2009 at 10:05 AM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,456

    Re: Chart macro

    Chart sheets do not have a cells property.

    try this revised code
            bool2 = True
            
            If Cells(counter2, 1) <> Cells(counter2 + 1, 1) Then
                bool2 = False
                Sheets("Chart").Select
                ActiveChart.SeriesCollection.NewSeries
                With ActiveChart.SeriesCollection.NewSeries
                    .Name = Sheets("Temporary").Cells(position2, 1)
                    .Values = Sheets("Temporary").Range(Sheets("Temporary").Cells(6, position2), Sheets("Temporary").Cells(6, counter2))
                    .XValues = Sheets("Temporary").Range("A4:A14")
                End With
    
                
                Sheets("Temporary").Select
            End If
        Next
        
        Sheets("Chart").Select

  5. #5
    Registered User
    Join Date
    02-11-2009
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Chart macro

    That worked perfect! Thank you!

+ 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