Hello to everyone!
I tried to write a macro that re-sets the data range of my chart in Excel to the ith row. i is defined in cell G2. I don't know why my code (see below) isn't working (I get an error "Method Cells of Object _Global failed"). Can anyone help? I would very much appreciate it! Thank you! Fabian
Sub chart_range()
Dim i As Integer
i = Range("G2").Value
Worksheets("sheet1").ChartObjects(1).Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(Cells(2, 1), Cells(i, 4)), _
PlotBy:=xlRows
End Sub
I tried to write a macro that re-sets the data range of my chart in Excel to the ith row. i is defined in cell G2. I don't know why my code (see below) isn't working (I get an error "Method Cells of Object _Global failed"). Can anyone help? I would very much appreciate it! Thank you! Fabian
Sub chart_range()
Dim i As Integer
i = Range("G2").Value
Worksheets("sheet1").ChartObjects(1).Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(Cells(2, 1), Cells(i, 4)), _
PlotBy:=xlRows
End Sub