I want to loop plotting graph by using this code:
1 For i = 354 To 357
2 Range((Cells(208, 353)), Cells(219, 353)).Select
3 Range(Cells(208, i), Cells(219, i)).Select
4 ActiveSheet.Shapes.AddChart.Select
5 ActiveChart.ChartType = xlColumnClustered
6 ' ActiveChart.SetSourceData Source:=Range("Sheet2!Cells(208,354):Cells(219,354)")
7 ActiveChart.Axes(xlValue).MajorGridlines.Select
8 Application.WindowState = xlMaximized
9 ActiveChart.ApplyLayout (9)
10 Next i
11 End Sub
However, there is a runtime error in line 6, could anyone help please?
Cheers
In the problem line you need to set correct reference to sheet and range of cells. Therefore that line of code should look like:
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range(Cells(208,354),Cells(219,354))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.