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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

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