0

My Code:

Sub PieSourceData()
    Sheets("ReportSummary").ChartObjects("Chart 5").Activate
    Sheets("DataSheet").Select
    ActiveChart.SetSourceData Source:=Range("A245:B249")
End Sub

It is failing at the line :

ActiveChart.SetSourceData Source:=Range("A245:B249")
Community
  • 1
  • 1
user2242660
  • 33
  • 1
  • 2
  • 7

1 Answers1

2

The culprit is this line

 Sheets("DataSheet").Select

If you select that sheet then how is the chart active then ;)

And hence I always suggest to avoid the use of .Select. See this link.

Try this

Sub PieSourceData()
    Sheets("ReportSummary").ChartObjects("Chart 1").Activate
    ActiveChart.SetSourceData Source:=Sheets("DataSheet").Range("A245:B249")
End Sub
Community
  • 1
  • 1
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250