Vba Graphs/ Charts with Varrying Sheets

finaljustice

Board Regular
Joined
Oct 6, 2010
Messages
175
Hi!
I've been trying to generate a macro which automatically makes charts and graphs. I have been successfull to do this if I write it specifically a code for each Sheet I have, I figure there must be a way to code it to make it a generic code for all sheets.

My issue comes on this line:
Code:
ActiveChart.SetSourceData Source:=Range("'ZM1'!"$O$1,$AA$1,$AM$1,$BB$1,$BK$1,$BW$1,$CM$1,$CU$1,$DG$1"")

What I wonder if it can be done is if I can put a variable as the sheet when ordering it to get that data source. What will change will be the names of my sheets so "ZM1","ZM2", "ZM3".

What I tried unsuccessfully was:
Code:
x = ActiveSheet.Name
ActiveChart.SetSourceData Source:=Range("'x'!"$O$1,$AA$1,$AM$1,$BB$1,$BK$1,$BW$1,$CM$1,$CU$1,$DG$1"")

but VBA won't recognise X as a variable, that has the name of my desired sheet.


Any ideas?
Thank you for you attention.
Final
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try
Code:
x = ActiveSheet.Name 
Source:=Range("'" & x & "'" & "!$O$1........................
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

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