Macro: Change chart source data without using Activate

Naty

New Member
Joined
Jan 27, 2011
Messages
8
I'm trying to create a macro that changes the source data from specific cells for different cases. The button to run the macro is in Sheet1 and the charts are in Sheet2. My code so far is:

Sheets("Sheet2").ChartObjects("Chart 1").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B11:B17,T11:T17,AD11:AD17")


My problem is: I don't want Excel to go to Sheet2 when running the macro. In other words, I don't want to use the Activate method in the macro, I want the charts to update without going to Sheet2.

I thought this would work, but it doesn't:

Sheets("Sheet2").ChartObjects("Chart 1").SetSourceData Source:=Sheets("Sheet1").Range("B11:B17,T11:T17,AD11:AD17")

Any ideas? :confused:
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Why do you not want to use 'Activate'?
You can prevent the screen changing by using "Application.ScreenUpdating" and worksheet events from firing using "Application.EnableEvents".
 
Upvote 0
That's exactly what I wanted to prevent, the screen changing. I'll use Application.ScreenUpdating

Thank you!!!
 
Upvote 0
You left out a keyword:

Sheets("Sheet2").ChartObjects("Chart 1").Chart.SetSourceData Source:=Sheets("Sheet1").Range("B11:B17,T11:T17,AD11:AD17")
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top