I'm relatively new to VBA - tend to just go with stuff that works even if I don't understand it I'm afraid!
I'm trying to produce individual scatter graphs for each row of data from a worksheet. I'm OK with configuring the graph etc, but getting it to read each row and iterate properly is beyond me!
This is what I've got currently:
Private Sub CommandButton1_Click()
ActiveWorkbook.Charts.Add
Dim i As Integer
For i = 2 To WS.Range("A65536").End(xlUp).Row
With ActiveWorkbook.ActiveChart
    'Data?
    .ChartType = xlXYScatter
    .SeriesCollection.NewSeries
    .SeriesCollection(1).Name = "Progress"
    .SeriesCollection(1).XValues = "=Sheet2!$B$1:$J$1"
    .SeriesCollection(1).Values = "=Sheet2!$B$" & i & ":$J$" & i
    'Titles
    .HasTitle = True
    .ChartTitle.Characters.Text = "valuefromcellN2?"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Timeline"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Grade"
    .Axes(xlCategory).HasMajorGridlines = True
    'Formatting
    .Axes(xlCategory).HasMinorGridlines = False
    .Axes(xlValue).HasMajorGridlines = True
    .Axes(xlValue).HasMinorGridlines = False
    .HasLegend = False
End With
Next
End Sub
When I run this, I get a runtime error 424 - object required. My questions are:
- Am I going about this in roughly the right way?
- What have I missed out to cause this runtime error?
- How do I get the valuefromcellN2? to actually show the value, not text?
Thanks for any help!
Sam
EDIT:
thanks for the help - I think I've updated it correctly now (it works with all titles and creates new graphs!)
Private Sub CommandButton1_Click()
ActiveWorkbook.Charts.Add
Dim ws As Worksheet
Set ws = tracker
Dim i As Long
For i = 2 To ws.Range("A65536").End(xlUp).Row
Charts.Add
With ActiveWorkbook.ActiveChart
    'Data?
    .ChartType = xlXYScatter
    .SeriesCollection.NewSeries
    .SeriesCollection(1).Name = "Progress"
    .SeriesCollection(1).XValues = "=tracker!$B$1:$J$1"
    .SeriesCollection(1).Values = "=tracker!$B$" & i & ":$J$" & i
    'Titles
    .HasTitle = True
    .ChartTitle.Characters.Text = Range("N" & i).Value
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Timeline"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Grade"
    .Axes(xlCategory).HasMajorGridlines = True
    'Formatting
    .Axes(xlCategory).HasMinorGridlines = False
    .Axes(xlValue).HasMajorGridlines = True
    .Axes(xlValue).HasMinorGridlines = False
    .HasLegend = False
End With
Next
End Sub
 
     
    