title: Need fix for Excel VBA: The specified dimension is not valid for the current chart type
body: <p>My problem is as stated the specified dimension is not valid for the current chart type. </p>
  
  <p>But here is the strange thing ive used the same code on two different files and only doesn't work on one of the two files, this is done on Excel 2010. For example I used it in file a.xlsm it works fines does what it is supposed to do. But when I use it in file b.xlsm (converted from a .csv file), I keep getting this error, and a run-time error of '-2147352565(8002000b)'. </p>
  
  <p>My code is as follows:</p>
  
  <pre><code>Sub AddChartObject()
  Dim Cht As ChartObject
  
  Set Cht = ActiveSheet.ChartObjects.Add _
      (Left:=300, Width:=375, Top:=100, Height:=225)
  Cht.Chart.SetSourceData Source:=Sheets("Sheet1").Range("B2:B10")
  Cht.Chart.ChartType = xlXYScatterLines
  
  Worksheets(1).ChartObjects(1).Activate
  ActiveChart.HasTitle = True
  ActiveChart.ChartTitle.Text = "Testing"
  
  End Sub
  </code></pre>
  
  <p>I found it from here: <a href="http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html#topofpage" rel="nofollow noreferrer">http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html#topofpage</a></p>
  
  <p>And the error keeps pointing to this line</p>
  
  <pre><code> myChtObj.Chart.SetSourceData Source:=Sheets("Sheet1").Range("B2:B10")
  </code></pre>
  
  <p>there is another similar question on the site which is here <a href="https://stackoverflow.com/questions/11447914/vba-excel-the-specified-dimension-is-not-valid-for-the-current-chart-type">VBA Excel: The specified dimension is not valid for the current chart type</a> I did try the solution posted but it doesn't really work so would be appreciated if someone could point me in the right direction. </p>