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")

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Siddharth. It Worked !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.