title: Initializing chart object in crashes vba
body: <p>I'm currently writing a program that will create several charts by using a dataset. Every time I want to make a new chart, I call on a function. </p>
  
  <p>However when I go to initialize the chart object in that function, VBA just crashes and I have to terminate the program. </p>
  
  <p>Any idea why? I've tried initializing the chart object in my methods and it's the same result.</p>
  
  <p>Here's the code (as soon as it hits "Set chartSheet = Charts. Add", vba stops responding):</p>
  
  <pre><code>Function saccadeGraph(startRow As Long, sncol As Integer, sacol As Integer, iacol As Integer)
  
  Dim chartSheet As Chart
  Set chartSheet = Charts.Add
  
  Dim lastRow As Long
  lastRow = startRow
  
  ''Finds row where the slide ends
  While Cells(lastRow, sncol) = Cells(lastRow + 1, sncol)
      lastRow = lastRow + 1
  Wend
  
  With chartSheet
      .ChartType = xlLineMarkers
      .SetSourceData (Range(Cells(startRow, sacol), Cells(lastRow, sacol)))
      .SeriesCollection(1).XValues = Range(Cells(startRow, iacol), Cells(lastRow, iacol))
      ''modify when I'm able to know the index of the target IA
      .SeriesCollection(1).Points(3).Select
  End With
  
  With Selection.Format.Fill
      .Visible = msoTrue
      .ForeColor.RGB = RGB(192, 0, 0)
      .Transparency = 0
      .Solid
  End With
  
  saccadeGraph = 0
  
  
  End Function
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I ended up fixing the problem by initializing the chart like this:</p>
  
  <p><code>ActiveSheet.Shapes.AddChart.Select
   Set chartSheet = ActiveChart</code></p>
  
  <p>Still don't understand why what I initially wrote would cause vba to crash</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I jinxed myself, this new method now crashes vba too. It somehow worked once though, so I'm starting to wonder if it has to do with my computer</p>