I am writing a VBA function to automatically create a chart from a dataset.
Sub create_graph
     ActiveSheet.Shapes.AddChart.Select
     ActiveChart.ChartType = xlLine
     ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(1).Values = "='Blad1'!$F$1:$F$13"
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(1).Name = "=""Kosten"""    
End sub
This works fine. How I would like to make it more dynamic. So therefore I included:
    Range("B6").Select
    Set x = Range(Selection, Selection.End(xlDown))
So my code is like this now:
Sub create_graph
  ActiveSheet.Shapes.AddChart.Select
  ActiveChart.ChartType = xlLine
  ActiveChart.SeriesCollection.NewSeries
'Nog even kijken hoe ik dit dynamisch kan maken
    Range("B6").Select
    Set x = Range(Selection, Selection.End(xlDown))
   ActiveChart.SeriesCollection(1).Values = x
   ActiveChart.SeriesCollection.NewSeries
End sub
But his throws an error 91.
Any thoughts on what goes wrong?
 
     
    